AJAX in Web2py -> Synchronous

122 views
Skip to first unread message

Phoboss

unread,
Jan 27, 2011, 3:53:50 AM1/27/11
to web2py-users
Hi Experts,

how can I turn off asynchron AJAX in web2py?
It sounds strange but I need it synchronous!

BTW, I implemented this example:
http://www.web2py.com/book/default/chapter/10#Ajax-Form-Submission

Thank you so much!

Best Regards

Phoboss

DenesL

unread,
Jan 27, 2011, 9:49:43 AM1/27/11
to web2py-users
Hi Phoboss,

web2py uses the jQuery.ajax API which has a parameter named async for
that.

Try changing your app's web2py_ajax.html file where the jQuery.ajax
calls are made and specify async : false .

Denes

Phoboss

unread,
Jan 27, 2011, 9:54:25 AM1/27/11
to web2py-users
Hi Denes,

firstly thank you for your swift response!

I'm now at work. So in 4 hours or so I'll try it at home.
After that I'll report here if it's works.

Best Regards

Phoboss

Phoboss

unread,
Jan 27, 2011, 6:55:24 PM1/27/11
to web2py-users
OK, I tried to change the code of web2py_ajax.html BUT all function
code was commented out!! What is going on?
Why is all commented out? Is it commented out because all the code in
web2py_ajax.html is only for changing AJAX-settings? Like turning
asynchronisation off?
I built my app by using the form field "New simple application". After
that the web2py-system makes automatically a copy of the "welcome"-
app. And after that I never changed the web2py_ajax.html file!

Well, I commented "in" the "function ajax(u,s,t)".
Within this function there is the mentioned jQuery-Command:

jQuery.ajax({type: "POST", url: u, data: query, async: false, success:
function(msg) { if(t) { if(t==':eval') eval(msg); else jQuery("#" +
t).html(msg); } } });

So, finally it works now, however, I don't get why everything was
commented out.

Again, Thank you!

Regards

Phoboss

Anthony

unread,
Jan 27, 2011, 7:17:44 PM1/27/11
to web...@googlegroups.com
On Thursday, January 27, 2011 6:55:24 PM UTC-5, Phoboss wrote:
OK, I tried to change the code of web2py_ajax.html BUT all function
code was commented out!! What is going on?
 
 
Is your version the same? When you say the code is commented out, are you referring to the <!-- and //--> just inside the script tags? If so, that is commonly done so that older browsers that don't support Javascript won't end up displaying the Javascript code as if it were plain text (the opening and closing HTML comment tags tell the browser to ignore everything in between). See http://www.javascripter.net/faq/hidingjs.htm.
 
Anthony

Phoboss

unread,
Jan 28, 2011, 3:55:16 AM1/28/11
to web2py-users
Ohhh, OK, Anthony.
Yes, my version is the same.
And yes I'm reffering to <!-- and //--> .
I deleted them, because I thought it was for commenting out (nearly
everything was greyed out).

From your link:
"Old browsers will treat your JS code as one long HTML comment. On the
other hand, new JavaScript-aware browsers will normally interpret JS
code between the tags <script> and </script>"

Thank you for the clarification!

Best Regards

Phoboss

On 28 Jan., 01:17, Anthony <abasta...@gmail.com> wrote:
> On Thursday, January 27, 2011 6:55:24 PM UTC-5, Phoboss wrote:
>
> > OK, I tried to change the code of web2py_ajax.html BUT all function
> > code was commented out!! What is going on?
>
> Here's the file in trunk:http://code.google.com/p/web2py/source/browse/applications/welcome/vi...
Reply all
Reply to author
Forward
0 new messages