• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

loop through .getJSON

Hi Experts,

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


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

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

Open in new window

thanks in advance
1 Solution
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.

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

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now