tags:

views:

105

answers:

4

Hi,

I am working on adding asynchronous form submission inside a jquery dialog. I am using .ajax(). Everything is working correctly, but the submission takes longer than I would like. I am new to jquery and am unsure how to debug/optimize this. How do I determine if the lag is in the front or backend?

Thanks,

Natasha

+5  A: 

Although without some code there's no way to really know for your particular situation, any delays will not be with the Javascript unless you are doing something that will obviously take a lot of browser resources (sorting large tables, adding large amount of HTML, etc.) If all you're doing is grabbing the data, serializing it, and sending it over with AJAX over to the server and it is taking a long time to respond, then the problem is with the server-side code. You can verify this by using a tool like Firebug which shows you when the request is fired and how long it took for the server to answer once it does.

Paolo Bergantino
Tip: In Firebug, activate the 'Net' panel then activate the event. It'll also show you the parameters/POST data.
Lucas Jones
+4  A: 

If you have firefox use firebug, in the console tab it will show you how long the requet/response took, you can also (if you have access) log how long the back end process took, that should hopefully give you a reasonable idea of where the lag is.

Pharabus
+1 Firebug will give you all the timing information you need.
Jon Tackabury
A: 

Unless there's some awful code on the back-end, your speed issues are likely being caused by network issues. The JavaScript/Ajax isn't holding you back, or at least it doesn't intuitively seem likely.

Andrew Noyes
A: 

To determine where the slow down is, you can use the Date object to get the number of milliseconds at current (immediately after the form submit is clicked), then add a funciton beforeSend in jQuery.ajax({beforeSend: function() { ... }); adding the time since the start to a tag somewhere on the page. Then you can use complete to determine how long since the start.

jQuery.ajax options: http://docs.jquery.com/Ajax/jQuery.ajax#options

JS Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp

Darryl Hein