gpt4 book ai didi

php - 什么时候 404 不是 404?

转载 作者:可可西里 更新时间:2023-11-01 12:25:32 24 4
gpt4 key购买 nike

我正在使用下面的这个 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);
}

Here is the javascript console result

I'm able to call the file directly using the same URL the console reports as a 404

Header Report

这里是源文件,colorReset.php,它被调用...

<?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;
?>

最佳答案

作为 described in another answer ,加载 wp-blog-header.php 引导整个 WordPress 请求处理过程。鉴于您的脚本实际上不是 WordPress 帖子,此过程会设置 404 header 以指示它找不到您要查找的内容。

因为看起来您真正想要的只是访问 WordPress 用户函数,所以您最好只包含 wp-load.php,它应该允许您调用这些函数而无需调用请求解析器。

关于php - 什么时候 404 不是 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com