samedi 5 avril 2014

Accès au dictionnaire python en javascript - Stack Overflow



This question already has an answer here:




I am sending dictionary from python like this:


{'root':['value','path','type'],.......}

i am send it to javascript by ajax call request by serializing it,


How to access that dictionary in javascript.


thanks in Advance




Suppose you are making AJAX call in below way, you will get the response dict as resValue. use JSON.parse method on it


$.getJSON( "/url", {params }, function( data, status, xhr ) {
$.each(data.response, function(resKey, resValue){
if(resKey == "success"){
var _result = JSON.parse(resValue);
}
}
}



This question already has an answer here:




I am sending dictionary from python like this:


{'root':['value','path','type'],.......}

i am send it to javascript by ajax call request by serializing it,


How to access that dictionary in javascript.


thanks in Advance



Suppose you are making AJAX call in below way, you will get the response dict as resValue. use JSON.parse method on it


$.getJSON( "/url", {params }, function( data, status, xhr ) {
$.each(data.response, function(resKey, resValue){
if(resKey == "success"){
var _result = JSON.parse(resValue);
}
}
}

0 commentaires:

Enregistrer un commentaire