How To Get Each Value From Json Method
ajax $('#stb_no').blur(function(){ var stb_no= $('#stb_no').val(); $.ajax({ url: 'http://localhost/paymybill/ajax/stb_info', global: false, type: '
Solution 1:
Most browsers support JSON.parse(), which is defined in ECMA-262 and is the recommended way. Its usage is simple (I will use your example JSON):
var json = '{"area":"xxxxx",...,"email":"xxxxx@yahoo.com","amount":"xxx"}';
var obj = JSON.parse(json);
Note that obj.email can't be used, because you are parsing an array.
Edit: Checking your comments you need to know that the data parameter is the JSON object, parse it first and then you can do:
$('#amount').val(obj[0].email);
Solution 2:
Just add to $.ajax
call parameter dataType:"json"
and Jquery will parse it in success parameter automatically. Then use it data[0]['email'];
Solution 3:
For example :
$('#stb_no').blur(function(){
var stb_no= $('#stb_no').val();
$.ajax({
url: "http://localhost/paymybill/ajax/stb_info",
global: false,
type: "POST",
data: {
'stb_no':stb_no, // you should give a key to the variable
},
success: function(data) {
$('#email').val(data[0]['email']);
//ORvar obj = JSON.parse(data);
$('#email').val(obj[0].email);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
});
Post a Comment for "How To Get Each Value From Json Method"