Wordpress admin-ajax.php返回php代码而不是json

时间:2016-04-26 07:00:31

标签: php json ajax wordpress nginx

如何让WordPress在Nginx上返回JSON?

在我的wordpress中,Ajax调用返回<?php JSON而不仅仅是JSON。 该网站工作得很好,除了admin-ajax调用。

定期通话 SessionSniff

文件上传通话 FileUploadSniff

TechInfo:

Wordpress 4.5
PHP 5.6.11-1ubuntu3.1 (fpm-fcgi)
nginx version: nginx/1.9.3 (Ubuntu)

标题嗅探

Request URL:http://SERVER/wp-admin/admin-ajax.php
Request Method:POST
Status Code:200 OK
Remote Address:IP:80
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://SERVER
Cache-Control:no-cache, must-revalidate, max-age=0
Connection:keep-alive
Content-Type:application/json; charset=UTF-8
Date:Tue, 26 Apr 2016 06:44:17 GMT
Expires:Wed, 11 Jan 1984 05:00:00 GMT
Pragma:no-cache
Server:nginx/1.9.3 (Ubuntu)
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Robots-Tag:noindex
Request Headers
view source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,pl;q=0.6
Connection:keep-alive
Content-Length:107
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:REDACTED ;)
Host:SERVER
Origin:http://SERVER
Referer:http://SERWER/wp-admin/media-new.php
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
view source
view URL encoded
data[wp-auth-check]:true
interval:60
_nonce:32b36eaa97
action:heartbeat
screen_id:media
has_focus:false

NGINX

location / {
    index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
}

2 个答案:

答案 0 :(得分:1)

关闭此主题。 问题是在functions.php文件中没有评论 将以下内容添加到functions.php后,问题就消失了。

<?php
/**
 * Twenty Fifteen functions and definitions
 *
 * Set up the theme and provides some helper functions, which are used in the
 * theme as custom template tags. Others are attached to action and filter
 * hooks in WordPress to change core functionality.
 *
 * When using a child theme you can override certain functions (those wrapped
 * in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before
 * the parent theme's file, so the child theme functions would be used.
 *
 * @link https://codex.wordpress.org/Theme_Development
 * @link https://codex.wordpress.org/Child_Themes
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are
 * instead attached to a filter or action hook.
 *
 * For more information on hooks, actions, and filters,
 * {@link https://codex.wordpress.org/Plugin_API}
 *
 * @package WordPress
 * @subpackage Twenty_Fifteen
 * @since Twenty Fifteen 1.0
 */

答案 1 :(得分:0)

检查wordpress文件是否未被泄露。您可能在核心Wordpress文件中进行了一些修改,添加了#34;

全新安装Wordpress文件并检查它是否仍然存在。 对wordpress的所有修改都应该在主题文件夹或插件中完成。

我仍然出现问题尝试禁用所有插件并逐个打开。其中一个插件可能搞乱了。