2 Replies - 1039 Views - Last Post: 12 December 2011 - 04:50 AM

#1 pjeddy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-December 11

Delay in jquery requests, is it my code or the server?

Posted 11 December 2011 - 05:02 PM

I am using JQuery to populate a drop-down menu based on a previous drop-down menu selection.

When the user selects a 'Specialty', the script recognizes the change event and calls a PHP page passing that Specialty ID. The PHP page then generates 'Sub-Specialty' options based on that ID. The response is sent back and the 'Sub-Specialty' drop-down is populated.

The script functions; however, there is a reasonably long delay for the items to load when the 'Specialty' drop-down changes. Could this be an issue with the hosting company server or my code (note: checked the PHP/MySQL code alone and loads very fast)?

Here is the code (it was once inside document. ready but took it out thinking it would speed things up -- did not):
$(function(){	
	 // If specialty drop-down menu changes
  $("#search_specialty").change(function(){
	  		// Show updating image
		  $("#updating").show();
		  // Request PHP page with specialty ID to generate show all related subspecialties
        $.ajax({
            type: "POST",
            data: "data=" + $(this).val(),
            url: "findspecialty.php",
            success: function(msg){
                if (msg != ''){
						 // Populate sub-specialty drop-down menu with repsonse
                    $("#search_subspecialty").html(msg).show();
						  $("#updating").hide();
                }else{

                }
            }
        });
  })
})



Any advice would help greatly.

Thanks for your time.

Is This A Good Question/Topic? 0
  • +

Replies To: Delay in jquery requests, is it my code or the server?

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Delay in jquery requests, is it my code or the server?

Posted 12 December 2011 - 04:41 AM

EDIT: Oops, I missed this

Quote

note: checked the PHP/MySQL code alone and loads very fast


rendering my answer below moot.

Are you on a slow computer? Is it still slow if you exit your browser completely and then re-open and go to the page? Could be memory leaks in the browser's JS implementation.

(FAILED ANSWER BELOW)
Chances are it's your PHP script, not jQuery. Run your PHP script outside of the web page (use something like REST Client for Firefox to build your request) and see if it's slow there too.
Was This Post Helpful? 0
  • +
  • -

#3 e_i_pi   User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: Delay in jquery requests, is it my code or the server?

Posted 12 December 2011 - 04:50 AM

Your jQuery code looks fine. I use AJAX requests all the time, with a jQuery AJAX function with much more going on than yours, and it runs fine. It could be your webhost.

Personally, I develop on a localhost, then push my code up to the live site. I find that to be a good way to judge whether your webhost is slow or not. Are you on a shared server? Shared servers can be disgutingly slow, especially during certain peak periods.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1