开发者

Fetch first element in 'new array' JSONP response with Jquery

开发者 https://www.devze.com 2023-01-15 18:07 出处:网络
I try to keep it simple: Problem: how to fetch the first element (weight here) from the new Array with JQuery

I try to keep it simple:

Problem: how to fetch the first element (weight here) from the new Array with JQuery

Current 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 response:

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


That response isn't JSONP, but may work (never tried the approach), your callback should be looking for the second parameter though, like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消