Sco*_*t B 8 php apache jquery http-status-code-404
我正在使用下面的jQuery调用来加载位于同一服务器上的.php文件.
但是,使用Chrome的javascript控制台,它在我试图加载的php文件上报告"404 not found".虽然,我可以直接加载文件,只需在控制台中单击该文件即可.
此外,我可以直接从它报告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);
}
Run Code Online (Sandbox Code Playgroud)



这是源文件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;
?>
Run Code Online (Sandbox Code Playgroud)
您可能希望查看收到的响应的标题.发送带有404响应的文档并不罕见,浏览器可能会显示该响应.但它仍然是一个404响应,而JQuery会将其视为一个错误(根据它实际上是HTTP标准).
| 归档时间: |
|
| 查看次数: |
2440 次 |
| 最近记录: |