loop through .getJSON

Hi Experts,

I am trying to loop through with .getJSON() and I am trying to manipulate this:

http://jsfiddle.net/pxfunc/j3AN7/


This is the code from JSP in the project that I am working on:

 $(function() {    
        $("#tags").autocomplete({
        	minLength: 3, //at leat 3 char required
            source: function (request, response) {
                $.getJSON("AutoCompleteController", {
                    term: request.term
                }, response);
            } 
           
        })
    });

Open in new window


thanks in advance
dkim18Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Given that snippet, the autocomplete will attempt to pull its source data from ./AutoCompleteController, with GET variable term.  The third parameter is to $.getJSON() is supposed to be a success callback, and you are passing it the response function provided by the autocomplete library.  The response function, in turn, requires its own parameter - the data you just pulled from the AJAX request.  So, switch that out with a delta function wrappe.  The example below is from working code on one of my projects.  I use $.ajax instead of $.getJSON, but 6 in one hand and such.

   $('#quick-search-term').autocomplete({
		      	minLength: 1,
		      	source: function( req, resp ) {
		      	  $.ajax({
		      	           url : DJQ.ajax_url,
		      	           dataType: "json",
		      	           type:'POST',
		      	           data: $.param({ fragment:req.term, requestType:'wordlist' }),
		      	           success: function(d) {
		      	             resp( $.map(d.words,function(i) { return i; }) );
		      	           }
		          });
		      	}
    });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.