我尽量保持简单:
问题:如何使用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);
答案 0 :(得分:0)
该响应不是JSONP,但可能有效(从未尝试过该方法),您的回调应该是寻找第二个参数,如下所示:
callback_function = function(something, suggestions, somethingElse)
{
return suggestions[0];
}