首页 > 解决方案 > 仅在传递任何数据时 Ajax Post 错误 500

问题描述

仅当我通过任何错误时才会发生错误

数据 : ,

到我的ajax。我试图把它放在 URL 中,在一个数组中,更改名称,......没有任何改变结果。如果我删除数据,我会得到正确的 200 状态响应。

如果我直接访问该页面,没问题,仍然是干净的 200。

我的ajax函数:

$( "#deleteMool" ).click(function() {

                $.ajax({
                    url : '/Trunk/SofastBS/mool-delete',
                    type : 'POST',
                    data : 'mool=' + '4'  ,
                    dataType : 'html' ,
                    success : function(code_html, statut){

                        if (code_html == 'OK') {

                            location.reload();

                        }   
                    },
                });

        });

我的 PHP 页面:

<?php

$ID = $_POST['mool'];

// Check if user is logged in 
if ( is_user_logged_in() ){

    /*.................. Empty request block ...............*/
    if ($ID != ''){

        $mool_id = delete_mool( $ID ) ;

        //On success
        if ( $mool_id == true ) {
            echo 'OK';
        }
        else{

            echo 'Une erreur est survenue.';

        }
    }
    else {

        header('Location: '.site_url());
        echo 'ID EMPTY';

    }
}
else {

    header('Location: '.site_url());
    echo 'NOT LOGGED IN';

}   

我的标题:

响应头:

HTTP/1.0 500 Internal Server Error
Date: Tue, 29 Oct 2019 10:19:37 GMT
Server: Apache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Link: <http://192.168.1.95/Trunk/SofastBS/wp-json/>; rel="https://api.w.org/"
Link: <http://192.168.1.95/Trunk/SofastBS/?p=400>; rel=shortlink
Content-Length: 1
Connection: close
Content-Type: text/html; charset=UTF-8

请求头:

POST /Trunk/SofastBS/mool-delete HTTP/1.1
Host: 192.168.1.95
Connection: keep-alive
Content-Length: 6
Accept: text/html, */*; q=0.01
Origin: http://192.168.1.95
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://192.168.1.95/Trunk/SofastBS/mool/
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_censored_by_me; wp-settings-1=mfold%3Do; wp-settings-time-1=1572342088; PHPSESSID=65hhsmd6290lrei04se2tc8c93

为了进行比较,我在另一个 Web 部件、另一个站点上使用了相同的代码,并且工作完美:

以下是工作位的标题:

响应头:

HTTP/1.1 200 OK
Date: Tue, 29 Oct 2019 10:29:38 GMT
Server: Apache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Link: <http://192.168.1.95/trunk/nagacount/wp-json/>; rel="https://api.w.org/"
Link: <http://192.168.1.95/trunk/nagacount/?p=79>; rel=shortlink
Content-Length: 2
Keep-Alive: timeout=5, max=95
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

请求头:

POST /trunk/nagacount/mool-delete HTTP/1.1
Host: 192.168.1.95
Connection: keep-alive
Content-Length: 5
Accept: text/html, */*; q=0.01
Origin: http://192.168.1.95
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://192.168.1.95/trunk/nagacount/mool/
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_censored_by_me; PHPSESSID=65hhsmd6290lrei04se2tc8c93

我被困了一会儿,我确定我错过了一些东西,但我找不到它。有什么提示吗?

标签: ajax

解决方案


推荐阅读