Home > Backend Development > PHP Tutorial > Ajax request php reports error 404 but the script can output data normally. Solution to the problem_PHP tutorial

Ajax request php reports error 404 but the script can output data normally. Solution to the problem_PHP tutorial

WBOY
Release: 2016-07-13 09:55:59
Original
1664 people have browsed it

Ajax request to php reports error 404 but the script can output data normally. Solution to the problem

1. Scene

Ajax requests the php script to return a 404 status code, but the php script can output data, causing the ajax callback function to be unable to continue execution.

Troubleshooting process:

1. I suspect that there is a problem with the framework I wrote. I request the ajax request script path in the browser window and the page can be opened normally.

2. Write a php script, directly output a string in json format, use ajax to request, and still return status code 404.

3. Write an html page and use ajax to request it. The return status code is 405.

4. Check the nginx configuration parameters and find that there is a problem with the fastcgi configuration.

Solution:

 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;
        }
Copy after login

changed to

 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;
        }
Copy after login

Modification content:

root runs the root directory for the website.

/scripts Change to the website root directory.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990599.htmlTechArticleajax request php error 404 but the script can output data normally Solution to the problem 1. Scenario ajax request php script returns 404 status code, but the php script can output data, resulting in ajax's response...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template