Discussion:
unable to call ajax url from external javascript.
Pradeesh
2012-02-20 15:08:42 UTC
Permalink
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
Anthony
2012-02-20 15:55:21 UTC
Permalink
Post by Pradeesh
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
The ajax() function is in web2py.js. When you call it from an external js
file, has web2py.js already been loaded in the page?

Anthony
Alan Etkin
2012-02-20 20:01:39 UTC
Permalink
Maybe wrapping the code in jQuery(document).ready() the execution is
delayed enough time for the web2py functions to be read.
Post by Pradeesh
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
Vineet
2012-02-21 04:13:57 UTC
Permalink
In your statement --
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');

comma is missing after URL and before ['name'].
Check whether it is a typo or otherwise.

-- Vineet
Post by Alan Etkin
Maybe wrapping the code in jQuery(document).ready() the execution is
delayed enough time for the web2py functions to be read.
Post by Pradeesh
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
Vineet
2012-02-21 04:16:04 UTC
Permalink
In your statement --
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');

comma is missing after URL and before ['name'].
Check whether it is a typo or otherwise.

Secondly, double check whether the external js file is included in the
header section of layout.html

-- Vineet
Post by Alan Etkin
Maybe wrapping the code in jQuery(document).ready() the execution is
delayed enough time for the web2py functions to be read.
Post by Pradeesh
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
zhongliang liang
2013-02-24 20:26:16 UTC
Permalink
Emmm.... I'm not sure you can do this in external js files.

URL(...) and "{{ ... }}" markup are python helpers defined in web2py, they
are only visible in python controller files and view files that will be
rendered by web2py framework. Static external js files are only plain js,
which wont be rendered by web2py. So the above "{{=URL(...)...}}" is only a
plain string to javascript.

However, ajax() is a javascript function defined by web2py.js, so it's
visible in js files. So just use the direct url instead of the markup. The
following code in static js files should do what you want:

ajax("control2/function1", ['name'],'target')

ps: I realized this is an old thread, but the comment may help future users
who google for similar problems.
Post by Pradeesh
I am new to web2py.
form my view i am able to call web2py ajax as "
ajax("{{=URL(r=request,c='control2',f='function1')}}"['name'],'target');
". But the same command is not working from an external javascript.
How can i call a function (in another control file) using ajax from an
external JavaScript.
--
---
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 web2py+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...