Actually I'm trying to a send ajax call with a data array. This is my sample code, criteria is an array but when I send this call it doesnt return any data. but when I tried it using php it worked perfectly. This is my sample php code
$post = array('criteria'=>array('user_id'=>'user1','subject'=>'meeting'));
$fields = (is_array($post)) ? http_build_query($post) : $post;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mydomain/task/find');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$serverOutput = curl_exec ($ch);
curl_close ($ch);
error_log('>>>>>>>>>>>>>>>>'.$serverOutput);
So what is the mistake of following code? How can I send an array using ajax ? please help me.
$.ajax({
type: "POST",
url: "http://mydomain/task/find",
data: { "criteria" : [{'user_id':'uesr1'},{'subject':'meeting'}]},
success: function(data) {
if (data.status) {
alert('ok');
}
},
dataType: 'json',
});
actually this works for single element like this,
$.ajax({
type: "POST",
url: "http://mydomain/task/find",
data: { "criteria" : [{'user_id':user1}]},
success: function(data) {
if (data.status) {
}
},
dataType: 'json',
});