【问题标题】:Fetch first element in 'new array' JSONP response with Jquery使用 Jquery 获取“新数组”JSONP 响应中的第一个元素
【发布时间】:2010-09-13 13:22:36
【问题描述】:

我尽量保持简单:

问题:如何使用 JQuery 从新数组中获取第一个元素(此处为权重)

当前的 JQuery:

function xyz() 
{
            var the_url = 'http://longurl'+encodeURIComponent(searchBox.val());

            var x1 = $.ajax({
                   type: "GET",
                   url: the_url,
                   dataType: "script"
            });
}

callback_function = function(suggestions)
{
    return suggestions[0];
}

JSONP 响应:

callback_function("w", new Array("weight", "weight loss", "wound"), 0);

【问题讨论】:

    标签: jquery arrays json jsonp


    【解决方案1】:

    该响应不是 JSONP,但可能有效(从未尝试过该方法),但您的回调应该寻找 second 参数,如下所示:

    callback_function = function(something, suggestions, somethingElse)
    {
      return suggestions[0];
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 2010-12-27
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      相关资源
      最近更新 更多