简体   繁体   English

jQuery Ajax Post-JSON适用于GET,但不适用于POST

[英]JQuery Ajax Post - JSON works with GET but NOT with POST

I am trying to send json string to the server using jquery ajax, as below. 我正在尝试使用jquery ajax将json字符串发送到服务器,如下所示。 It decodes correctly when GET is used, but does not work when POST is used. 使用GET时,它可以正确解码,但是使用POST时,它不起作用。 Any suggestions? 有什么建议么?

    $.ajax({
    type: "GET",
        url: "../pssops21/php/insertTempTransData.php",
        data: 'data=' + strSelectedItems,
        dataType: 'json',
        async: false,
        success: handleresponse                 
    }); 

Server side php: 服务器端php:

$json = json_decode(stripslashes($_POST['data']), true);

After the comments, I realize it is not an ajax post issue, but a decoding issue. 在评论之后,我意识到这不是ajax发布问题,而是解码问题。

Thank you. 谢谢。

我认为在服务器端,您需要$ _POST ['strSelectedItems']而不是$ _POST ['data'] ..或执行print_r($ _ POST)以获得更清晰的图片,我认为js可以,但是我不是jQuery专家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM