Yea, the ajax running synchronously - you provide callbacks because they do run asynchronously. To quote the jQuery book:
The* first letter in Ajax stands for "asynchronous,"* meaning that the operation occurs in parallel and the order of completion is not guaranteed. The async option to $.ajax() defaults to true, indicating that code execution can continue after the request is made. Setting this option to false (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive. Just what kind of app do you have that needs to make synchronous requests? Why are you not batching requests and processing async? On Wednesday, November 6, 2013 4:32:54 PM UTC-7, Ricardo Pedroso wrote: > > On Tue, Nov 5, 2013 at 11:53 AM, Andrew Buchan <[email protected]<javascript:> > > wrote: > >> Ok, the IT guy has disabled McAffee's "on access" scan for the folders >> containing web2py stuff as well as python's installation directory. He >> tells me that parts of McAffee other than "on access" scan may still >> interfere but there's not much we can do about that. This hasn't made any >> difference. >> As for the ajax calls, I thought it might be to do with the asynchronous >> calls taking too long when the server is overloaded (and it seems it is >> being hammered intermittently by another application), but I checked my >> web2py_ajax.html file and the ajax function is set to "async: false", so >> there shouldn't be an issue there unless there is some kind of timeout that >> kicks in? >> >> But.... I was about to post the above when I did some checks on the ajax >> calls, and am a bit confused... >> I have two javascript functions which call ajax: >> >> #Function1: This call displays a check list of 'previous contracts' to >> pick from >> ajax('HubForms/Timesheets/AjaxReturnBlank', [], >> 'PreviousContractListingArea'); >> >> #Function2: Once user has check some items, they click a button to call >> this, which adds all selected contracts to timesheet, then reloads the page. >> jQuery('.PreviousContractCheckbox').each( >> function(index) >> { >> if(this.checked) >> { >> jQuery('#ContractId').val(this.name); >> ajax('HubForms/Timesheets/AjaxAddContractToTimesheet', >> ['ContractId', 'TimesheetId', 'UserId']); >> } >> } >> ); >> a='nothing, just works'; >> window.location='HubForms/Timesheets/ViewTimesheet?Timesheet_Id=15995'; >> location.reload(true); >> >> I temporarily modified the ajax function in web2py_ajax.html to display a >> pop-up, then wait 3 seconds before executing (last 4 lines modified): >> >> function ajax(u,s,t) { >> var query=""; >> for(i=0; i<s.length; i++) { >> if(i>0) query=query+"&"; >> >> >> query=query+encodeURIComponent(s[i])+"="+encodeURIComponent(document.getElementById(s[i]).value); >> } >> /*this line: >> jQuery.ajax({type: "POST", url: u, data: query, async: false, >> success: function(msg) { if(t==':eval') eval(msg); else >> document.getElementById(t).innerHTML=msg; } }); >> replaced by these 4 lines: >> */ >> alert('hi'); >> setTimeout(function(){ >> jQuery.ajax({type: "POST", url: u, data: query, async: false, success: >> function(msg) { if(t==':eval') eval(msg); else >> document.getElementById(t).innerHTML=msg; } }) >> },3000); >> } >> >> The funny thing is that my Function1 does this (says 'hi' then pauses for >> 3 seconds), but Function2 says 'hi' for every item selected as you'd >> expect, but does NOT pause... >> This is making me wonder whether web2py's ajax function behaves >> differently when called from inside jQuery().each() as the setTimeout() >> is being ignored...? >> > > I don't have a solution for your problem, if you could make a minimal > application that replicates the problem, it would > be easy to track it down. > > setTimeout will not pause javascript execution, it will only put the given > function in a "queue" to be processed later. > > Why are you doing an ajax call for each item checked? > I think you could just make one ajax call with a list of checked items, it > would be more efficient. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

