Sorry if this gets posted twice. I thought I submitted it earlier, but it
seems to have disappeared. I have a very basic question about using the
ajax() and :eval. I am working through a very basic test where I have a
view, that when its completely loaded will call a function in the
controller. That function will build a string and return it to be evaluated
into a Javascript variable that can be further used throughout the view.
I have the following code in my view:
<script>
$( document ).ready(function() {
ajax('fetch', [], ':eval');
});
document.write(data);
</script>
and the controller function is this:
def fetch():
## fetch string here when called by the view using AJAX
test = "It Works!"
result = "var data = %s;" % test
return result
This seems reasonable to me, but it gives me two errors. The first is a
"Uncaught
ReferenceError: data is not defined ". The second is: "Uncaught
SyntaxError: Unexpected token < "
I believe the first error might be being caused in some way by the second,
in that data isn't defined because something is going wrong with the ajax
call and :eval argument? Though with this simple example I haven't
discovered what that might be.
Any help would be greatly appreciated.
Cheers,
- Lyndon
--
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.