Send and receive data in same ajax request with jquery

Posted by Pedro Esperança on Stack Overflow See other posts from Stack Overflow or by Pedro Esperança
Published on 2012-10-18T22:56:48Z Indexed on 2012/10/18 23:00 UTC
Read the original article Hit count: 167

Filed under:
|
|

What is the best way to send data and receive a response dependent on that data?

Consider the php file used for the request:

 $test = $_POST['test'];

 echo json_encode($test);

I have tried unsucessfully to achieve this with:

 $.ajax({
 type: "POST",
 dataType: "json",
 data: '{test : worked}',
 url: 'ajax/getDude.php',
 success: function(response) {
     alert(response);             
                             }
 });

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery