douyo770657 2018-02-27 16:24
浏览 353

指定为POST的jQuery AJAX调用被识别为GET

I have an jQuery AJAX call like so:

var ajaxStuff = $.ajax({
    type : 'POST',
    url : customURL,
    data : {
        myData : 'myData'
    },
    dataType : 'json',
    async : false
}).responseText;
console.log(ajaxStuff);

However, in the PHP when I ask what request method I'm using:

echo ($_SERVER["REQUEST_METHOD"]);

It returns:

GET

Why can't my AJAX call be recognized as a POST?

Thanks!

  • 写回答

1条回答 默认 最新

  • doufeng2877 2018-02-27 16:29
    关注

    The parameter name of the method is method, not type:

    var ajaxStuff = $.ajax({
        method: 'POST',  ////// not "type"
        url : customURL,
        data : {
            myData : 'myData'
        },
        dataType : 'json',
        async : false
    }).responseText;
    console.log(ajaxStuff);
    

    Docs: http://api.jquery.com/jquery.ajax/

    $.ajax() defaults to GET when no method is specified, or when the parameter is named incorrectly.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器