Organizational Research By

Surprising Reserch Topic

How to get JSON key and value with ajax


How can I get the key and value from that json with ajax?

 

 type="text/javascript">
$(document).ready(function(){
$.ajax({
    type: 'POST',
    url: '--url--',
    dataType: 'text',
    success: function(jsonData) {
        $.each(response,function(index,value)
        {
            $("[name="+index+"]").val(value);
        });
    }
});
});

asked Jun 3, 2015 in JAVASCRIPT by rajesh
0 votes
73 views



Related Hot Questions

2 Answers

0 votes

Try changing the .success() part:

.success: function(jsonData) {
    var response = JSON.parse(jsonData);
    console.log(response);
}

And remove dataType: 'text',.

You should see the object in your browser console and should be able to iterate with .each() from then on. Please share your results.

answered Jun 3, 2015 by rajesh
0 votes

i think you want this:

$.each(response,function(key,value){

    console.log(key":"+value.name);
    console.log(key+":"+value.address);

})
answered Jun 3, 2015 by rajesh

...