简体   繁体   English

getJSON回调将不起作用

[英]getJSON callback won't work

I'm pretty knew to creating JSON objects and passing them on to the browser. 我很清楚创建JSON对象并将其传递给浏览器的知识。 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: 正在进行调用,并且返回状态200和JSON对象:

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'). 但是,即使只有一个简单的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. 文档说数据对象-您的第二个参数-应该是一个普通对象,并在将其附加到url之前转换为字符串并进行url编码。 Try this: 尝试这个:

$('#id').change(function(){
    var url = 'ajax.cfm?callback=?';
    var data = { id: $(this).val() };
    $.getJSON(url, data, function(data){
        console.log('here');
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM