• 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:

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
0
dkim18
Asked:
dkim18
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.

   $('#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
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