tags:

views:

531

answers:

1

Hello All:

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.

+2  A: 

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.

Sabeen Malik
do print_r($_POST) to see what's being sent as proposed above
dusoft
Sorry, that was a posting mistake. I changed the variable names later.
Natkeeran
@Natkeeran ... if you use firefox , i would suggest you look in the firebug console and see what sort of parameters are being sent. and if i understand correctly u have already tried print_r($_POST) on the receiving end?
Sabeen Malik
Yes, firebug posts this:data [[{"TransactionID":"00425", "EndDate":"2009-12-31"}]]I realize the issue in the decoding side, for some reason json_decode works with GET, and not with POST as expected.
Natkeeran
can u please post the exact and complete output of print_r($_POST)
Sabeen Malik