Hi All:
Currently I am working on a ajax-based web application that does some XHR.
I chose CakePHP + jQuery to do the jobs, they work pretty well except this little problem.
Say, I make a String of a valid JSON form ==> { "test" : "hello world"}
Then I am calling jQuery's ajax method to send it to the destination php page:
jQuery.ajax
({
type: 'POST',
cache: false,
async: false,
timeout: 10000,
url : 'http://localhost/method/',
dataType : 'json', //defines expected response datatype
contentType : 'application/json', //defines request datatype
data : { "test" : "hello world"},
success : function(json)
{
//do some stuff here.
}});
Previously I tried this ajax function with empty data (i.e. just use data : {} since this is a POST), and it worked just fine; however, now that I've added a json-formatted data to the HTTP POST, is there a way to refer to it from the PHP script's side?
I tried : data : { "data" : {"test" : "helloworld"}}
I use PHP's isset[$_POST['data'] to check, and the result is POST variable 'data' is unset.
Can anyone give me a way to solve this problem? Many thanks in advance!!!