【发布时间】:2011-09-06 09:02:54
【问题描述】:
我正在使用下面的这个 jQuery 调用来加载位于同一服务器上的 .php 文件。
但是,使用 Chrome 的 javascript 控制台,它在我尝试加载的 php 文件上报告“404 未找到”。虽然,我可以直接加载文件,只需从控制台中单击文件即可。
另外,我可以直接从报告 404(未找到)的 javascript 控制台复制文件的 URL,打开一个新选项卡,将其粘贴到地址栏中,然后点击脚本,没有问题。
这是 jQuery get 方法特有的吗?什么可能导致get方法中的页面为404,但直接调用时执行正常?
$('.colorReset').click
(
function()
{
var myImage = $('#theme :selected').text();
$.get('<?php echo get_bloginfo('template_directory') ?>/colorReset.php', {theme: myImage, spot: '1'}, function(data){doColor('#theme_header_color', data);});
}
);
//script never gets to the doColor function, due to the apparent 404 on colorReset.php
function doColor(el, color)
{
$(el).val(color).trigger('keyup');
$(el).attr('value', color);
$(el).val(color);
}
这里是源文件colorReset.php,由get调用...
<?php
require_once('../../../wp-blog-header.php');
add_action( 'admin_init', 'check_user' );
function check_user()
{
if (!is_user_logged_in()){
die("You Must Be Logged In to Access This");
}
if( ! current_user_can('edit_files')) {
die("Oops sorry you are not authorized to do this");
}
}
$myTheme = $_REQUEST['theme'];
$spot = $_REQUEST['spot'];
$myThemeColor = $myTheme."_color".$spot;
$file = "styles/".$myTheme."/template.ini";
if (file_exists($file) && is_readable($file))
{
$ini_array = parse_ini_file($file);
if($spot == 1){$myColor = $ini_array['color1'];}
if($spot == 2){$myColor = $ini_array['color2'];}
if($spot == 3){$myColor = $ini_array['color3'];}
if($spot == 4){$myColor = $ini_array['color4'];}
}
else
{
if($spot == 1){$myColor = get_option('theme_header_color');}
if($spot == 2){$myColor = get_option('theme_sidebar_color');}
if($spot == 3){$myColor = get_option('theme_spot_color_alt');}
if($spot == 4){$myColor = get_option('theme_spot_color_alt2');}
}
echo $myColor;
?>
【问题讨论】:
-
那肯定有很多标签。
-
我想我会对标签感到厌烦。我想我是浏览器“打包老鼠”:-)
-
你可能想看看你的情况是否和this one类似。
-
为什么地址如此秘密?你应该比较这两个地址。顺便说一句
$.get('<?php echo get_bloginfo('template_directory') ?>...这看起来真的很难看。你不应该像这样将 javascript 与 php 混合使用。 -
@Jamie:chrome 内置了一些非常好的开发者工具。点击
ctrl-shift-i将它们提出来。
标签: php jquery apache http-status-code-404