This below methods are used to convert json data to j query objects
Assuming your server side script doesn't set the proper Content-Type: application/json response header you will need to indicate to jQuery that this is JSON by using the dataType: 'json'parameter
$.ajax({
type: 'GET',
url: 'http://example/functions.aspx',
data: { get_param: 'value' },
dataType: 'json',
success: function (data) {
$.each(data, function(index, element) {
$('body').append($('<div>', {
text: element.name
}));
});
}
});
or use the $.getJSON method:
$.ajax({
type: 'GET',
url: 'http://example/functions.php',
data: { get_param: 'value' },
dataType:'json',
success: function (data) {
var names = data
$('#cand').html(data);
}
});
$.getJSON( "ajax/test.json", function( data ) {
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
Comments
Post a Comment