jquery - Adding callback parameter to $.ajax with jsonp -
i trying implement jquery ajax call cross domain call using jsonp, , code -
$.ajax({ async:true, cached:true, url: 'cfcs/temprepository.cfc?method=getallcategories' +'&storeid='+ storeid +'&callback=?', type: 'get', data: '', datatype: 'jsonp', success: populatecategoryobject, error: function (xhr, status, error) { console.log(xhr + ',' + status + ',' + error); } }); function populatecategoryobject(results) { //populate categories }
i confused here use of callback. if remove success attribute of $.ajax , use callback=populatecategoryobject in place of callback=? -
$.ajax({ async:true, cached:true, url: 'cfcs/temprepository.cfc?method=getallcategories' +'&storeid='+ storeid +'&callback=populatecategoryobject', type: 'get', data: '', datatype: 'jsonp', error: function (xhr, status, error) { console.log(xhr + ',' + status + ',' + error); } });
the difference makes is, returns result -
populatecategoryobject, jquery172012112959187034678_1376976441013( // data here )
and, function populatecategoryobject not executed.
i unable figure out how set callback function here? , why "jquery172012112959187034678_1376976441013" getting added here result?
thanks in advance.
try
$.ajax({ cached:true, url: 'cfcs/temprepository.cfc?method=getallcategories' + '&storeid=' + storeid, jsonpcallback: 'populatecategoryobject', datatype: 'jsonp', error: function (xhr, status, error) { console.log(xhr + ',' + status + ',' + error); } });
Comments
Post a Comment