阿贾克斯()POST无法将数据发送到服务器端发送到、服务器端、数据、阿贾克斯

2023-09-11 01:23:12 作者:幼儿园扛把子

我的js侧面看像这样

$.ajax({
        type:"POST",
        data: {data:'abc'},
        url: "http://example.com/",
        success: function(result){
            console.log(result);
        }
    });

在我的PHP我做

header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

    $user_id = $_POST['data'];
    echo $user_id;

但我的成绩在控制台返回空白。

But my result in console returned blank.

要调试,我尝试回声'123',阿贾克斯也收到了123的价值,出了什么问题吗?

To debug, I try to echo '123', the ajax did received the value of 123, what has gone wrong here?

推荐答案

数据也应在报价

 $.ajax({
            type:"POST",
            data: {'data':'abc'},
           crossDomain: false,
            url: "http://example.com/",
            success: function(result){
                console.log(result);
            }
        });