我创建了一个简单的API虚拟页面:
add_action( \'init\', \'wpse9870_init_external\' );
function wpse9870_init_external()
{
global $wp_rewrite;
$plugin_url = plugins_url( \'api.php\', __FILE__ );
$plugin_url = substr( $plugin_url, strlen( home_url() ) + 1 );
$wp_rewrite->add_external_rule( \'api.php$\', $plugin_url );
}
add_action( \'init\', \'wpse9870_init_internal\' );
function wpse9870_init_internal()
{
add_rewrite_rule( \'api.php$\', \'index.php?wpse9870_api=1\', \'top\' );
}
add_filter( \'query_vars\', \'wpse9870_query_vars\' );
function wpse9870_query_vars( $query_vars )
{
$query_vars[] = \'wpse9870_api\';
return $query_vars;
}
add_action( \'parse_request\', \'wpse9870_parse_request\' );
function wpse9870_parse_request( &$wp )
{
if ( array_key_exists( \'wpse9870_api\', $wp->query_vars ) ) {
include \'api.php\';
exit();
}
return;
}
现在代码:
if(strpos($_SERVER[\'REQUEST_URI\'], "index.php?wpse9870_api=1"))
{
header("HTTP/1.1 200 OK");
echo "v1p";
}
页面在简单测试中工作并返回“v1p”,但标题为500,如果使用以下内容发表文章:
$.ajax({
type: \'POST\',
url: \'/index.php?wpse9870_api=1\',
返回错误时间:
错误:函数(响应){alert(JSON.stringify(响应));});
{"readyState":4,"responseText":"v1p","status":500,"statusText":"Internal Server Error"}
你能帮帮我吗?在更改服务器之前,现在我使用Apache 2.4.27和cPanel之前的LAMP。