Natkeeran
Natkeeran

Reputation: 1749

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. It decodes correctly when GET is used, but does not work when POST is used. Any suggestions?

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

Server side php:

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

After the comments, I realize it is not an ajax post issue, but a decoding issue.

Thank you.

Upvotes: 0

Views: 2068

Answers (1)

Sabeen Malik
Sabeen Malik

Reputation: 10880

i think on the server side you need to have $_POST['strSelectedItems'] instead of $_POST['data'] .. or do a print_r($_POST) to get a clearer picture , i think the js is ok, but i am not a jquery expert.

Upvotes: 2

Related Questions