views:

49

answers:

1

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);
A: 

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];
}
Nick Craver
That works! Great job Nick!
MeProtozoan