Wordpress admin-ajax.php返回php代码而不是json [英] Wordpress admin-ajax.php returns php code instead of json

查看:87
本文介绍了Wordpress admin-ajax.php返回php代码而不是json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使WordPress在Nginx上返回JSON?

在我的wordpress中,Ajax调用返回<?php JSON而不是简单的JSON. 该网站工作正常,除了admin-ajax调用.

In my wordpress, Ajax calls return <?php JSON instead just plain JSON. The site works just fine, except for admin-ajax calls.

常规通话

文件上传呼叫

技术信息:

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

推荐答案

只需关闭本主题. 问题是在functions.php文件中没有注释 将以下内容添加到functions.php后,问题消失了.

Just to close this topic. The problem was NO COMMENTS in functions.php file After I added the following to functions.php, the problem disappeared.

<?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
 */

这篇关于Wordpress admin-ajax.php返回php代码而不是json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆