Home  >  Article  >  php教程  >  ajax 请求php 报错404 但脚本能够正常输出数据 问题的解决方法

ajax 请求php 报错404 但脚本能够正常输出数据 问题的解决方法

WBOY
WBOYOriginal
2016-06-13 09:05:55878browse

ajax 请求php 报错404 但脚本能够正常输出数据 问题的解决方法

1、场景

ajax请求php脚本返回404状态码,但php脚本能够输出数据,导致ajax的的回调函数无法继续执行。

排查过程:

1、怀疑是自己写的框架有问题,在浏览器窗口中请求ajax的请求脚本路径,页面能够正常打开。

2、写个php脚本,直接输出一个json格式的字符串,用ajax请求,依旧返回状态码为404.

3、写个html页面用ajax请求,返回状态码为405.

4、排查nginx配置参数,发现fastcgi配置存在问题。

 

解决方法:

 

 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

 

更改为

 

 location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
            include        fastcgi_params;
        }

修改内容:

 

root 为网站运行根目录。

/scripts 更改为网站根目录。

 

 

 

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn