Reputation: 2099
Someone, ( @Denis ) helped me figure out this much, but I do not quite understand what load() really achieves or why the reference to "some_html" is done.
I think that Denis meant this to be the python code to load the site originally, as I understand it.
def some_html():
return render('my_template.tpl')
And this is the script which calls back python to get more data and it baffles me somewhat.
<script type="text/javascript">
$('#result_from_server').load('/some_html');
</script>
What I can't seem to understand is why the reference to the original Python method "/some_html" ? I would expect a reference to a new method in python, one which specializes in replying to that call from javascript.
The DIV with id=" result_from_server " I guess will act as a pseudo variable or container in HTML to receive the result. That is fairly clear, I think.
<div id="result_from_server"></div>
If anyone can help me understand how this request works I would appreciate it. I do understand that different types of data can be passed back from python. But I see no typing of any kind. I assume that means that this snippet is for passing text, then.
Upvotes: 0
Views: 1727
Reputation: 2924
'/some_html'
does not reference a Python method. It is as ignorant of Python as I am! In this case, it is the URL for the jQuery's ajax call (the load
method). I assume that your Python code's end result is mapping a code template to a URL.
Upvotes: 1
Reputation: 1929
Perhaps missing the "$" for jQuery?
<script type="text/javascript">
$('#result_from_server').load('/some_html');
</script>
This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data.
from: http://api.jquery.com/load/
Upvotes: 1