sending JSON to PHP using jquery ajax -


i'm sending simple compilation of object php script using jquery's .ajax. want extract 1 value each object in php script. javascript is:

var obj = [{id:1, name:"val1"}, {id:2, name:"val2"},{id:3, name:"val3"}];  $.ajax({             type: "get",             url: "call.php",             contenttype: "application/json",             data: {type: "stream", q: json.stringify(obj)},             success: function(response){                         alert(response);                      }           }); 

the call.php file written as:

if($_get['type']=='stream'){     $obj = json_decode($_get['q']);      for($i=0;$obj[$i];$i++){     echo $obj[$i]->{'name'}." ";     } } 

however returns 0, , cannot figure out why.

secondly attempted using type:"post" in javascript, , $_post in php, failed altogether.

 data: {type: "stream", q: json.stringify(obj)}, 

instead of use

 data: {type: "stream", q: obj}, 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -