I'm pretty knew to creating JSON objects and passing them on to the browser. For some reason, I'm not getting the callback to work.There is nothing on the console.
$('#id').change(function(){
$.getJSON('ajax.cfm?id='+$(this).val()+'&callback=?',null,function(data){
console.log('here');
});
});
The call is being made, and it is returning a 200 status and the JSON object:
configuratorsObj({
"Results" : 8,
"items" : [
{
vchrName: "Name1",
itemID: 1782
},
{
vchrName: "Name2",
itemID: 1769
},
{
vchrName: "Name3",
itemID: 1756
},
{
vchrName: "Name4",
itemID: 404
},
{
vchrName: "Name5",
itemID: 248
},
{
vchrName: "Name6",
itemID: 1743
},
{
vchrName: "Name7",
itemID: 5786
},
{
vchrName: "Name8",
itemID: 469
}
]})
But the call back won't work, even with just a simple console.log('here'). There are no errors on the console.
The docs say that the data object -- your second parameter -- should be a plain object and is converted to a string and url-encoded before it is appended to the url. Try this:
$('#id').change(function(){
var url = 'ajax.cfm?callback=?';
var data = { id: $(this).val() };
$.getJSON(url, data, function(data){
console.log('here');
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.