Results 1 to 3 of 3

Thread: Jquery w/ json search

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Jquery w/ json search

    I'm having a difficult time with my script, i'm newer to js also. The problem i'm having is the script will execute once just fine, however if you attempt to start the search over, it hangs.

    Code:
    $(document).ready(function(){
    	$('#keyword').bind('keyup',function(){
    		var keyword = $('#keyword').val();
    		var limit = $('#limit').val();
    		
    		if(keyword.length>3){
    			searchKeyword();
    		}
    		else if(keyword.length==0){
    			$('#searchResult').html('');
    			searchTerm='';
    		}
    	});
    	
    	$('#search').click(searchKeyword);
    	
    });
    
    var searchKeyword = function(){
    	var resultDiv =$('#searchResult');
    	var searchTerm = $('#keyword').val();
    	var resultLimit = $('#limit').val();
    	
    	resultDiv.html('<img src="/img/loading.gif">');
    
    	$.getJSON('/json/reports/master_report_search.php?limit='+resultLimit+'&keyword='+searchTerm,function(data){
    			
    			resultDiv.html('');
    			
    			resultDiv.append(data.length+' results for "'+searchTerm+'"');
    			
    			//filter through results
    			for (var i=0; i<data.length; i++){
    				
    				var row = '<div><a href="/reports/master/view.php?id='+data[i].id+'"> '+data[i].name + ' '+ data[i].date+'</a></div>';
    				
    				resultDiv.append(row);
    			
    			
    		}
    		
    	});
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,126
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    I might have to see the:

    /json/reports/master_report_search.php

    file, but I'm thinking the first result might be cached. To prevent that do:

    Code:
    $.ajaxSetup({
      cache: false
    });
    at the beginning, before the:

    Code:
    $(document).ready(function(){
    	$('#keyword').bind('keyup',f . . .
    The browser cache may need to be cleared and/or the page refreshed to see changes.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out. Oh, and I'd probably need to see that PHP file I mentioned as well, its code, as I cannot see that unless you provide it or a link to where you got it from.
    Last edited by jscheuer1; 07-05-2013 at 09:02 PM. Reason: fix typo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    Code:
    $.ajaxSetup({ cache: false });
    Did the trick!! Thank you :-)

Similar Threads

  1. Jquery $post JSON question
    By StealthRT in forum JavaScript
    Replies: 1
    Last Post: 07-26-2012, 01:19 PM
  2. JQuery search function failing
    By sniperman in forum JavaScript
    Replies: 0
    Last Post: 09-06-2011, 03:30 PM
  3. jquery/jscript website search function
    By neilkw in forum JavaScript
    Replies: 0
    Last Post: 10-26-2010, 11:37 AM
  4. jquery questions on # thingy and json
    By Rockonmetal in forum JavaScript
    Replies: 1
    Last Post: 05-28-2009, 08:45 PM
  5. Replies: 0
    Last Post: 04-06-2008, 08:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •