Jquery .load() function not responding with django

136 views
Skip to first unread message

Eli_West

unread,
Mar 14, 2012, 12:21:29 PM3/14/12
to Django users
I've ran into in issue where jquery .load() will load extra content by
directly opening html file in a browser but if served through Django
devel server the jquery load() is ignored. Have no idea what could be
happening but I've seen someone use a django url in the .load() call
instead of pointing .load() directly to a file:

<script>
$('.myClass').load('{% url update_dropdown %}',
{'kind': "Book" },
function(data){
alert(data);
});

</script>

He said he saw issues with a jquery library Any thoughts would be
great. BTW not a static file serving issue. Here is the very simple
code that works w/o django, but same thing loaded through django
fails:


///code from apress jquery, thanks to Bintu Harwani

////////basic jquery load function

$(document).ready(function() {
$('.list').click(function () {
$('#message').load('namesinfo.htm li');
return false;
});
});


/////////////basic html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8"/>
<title>JQuery Examples</title>
<script src="jquery-1[1].3.2.js" type="text/javascript"></
script>
<script src="d6.js" type="text/javascript"></script>
</head>
<body>
<p>We are going to organize the Conference on IT on 2nd Feb 2010</p>
<a href="abc.com" class="list">Participants</a>
<div id="message"></div>
</body>

//names info .htm with extra content to load
<p>The list of the persons taking part in conference </p>
<ul>
<li>Jackub</li>
<li>Jenny</li>
<li>Jill</li>
<li>John</li>
</ul>
<p>We wish them All the Best</p>

Daniel Roseman

unread,
Mar 14, 2012, 2:02:27 PM3/14/12
to django...@googlegroups.com
Where is that script in relation to your base html file? Is it directly included (if so, you don't show it)? Or is it being loaded as an external script? If so, you can't put Django template code (eg the {% url %} tag) in it, as it is not parsed as a template.
--
DR.

Eli_West

unread,
Mar 14, 2012, 10:39:15 PM3/14/12
to Django users

Thanks for the reply. It is loaded as an external script/file. That is
how it listed below right? Ive tried including it right in the file
too.

I think I know what you mean about using the url tag, I justed tried
this solution but with no results:

$(document).ready(function() {
$('.list').click(function () {

$('#message').load('{{ url testload}}');
return false;
});
});


which calls a django view to serve the page. Still does not work
however, unless I am doing it incorrectly. Could it be a jquery
library error. Here is my django view and url now:

def testload(request):
return render_to_response('tdcreative/testcontent.htm')

....
// in url conf
(r'^tdcreative/testload/$', 'tdcreative.views.testload'),

Eli_West

unread,
Mar 14, 2012, 10:59:51 PM3/14/12
to Django users
I just updated the jquery library so I shouldn't be that.

Ive got to be doing something wrong.. theres no way .load() simply
doesn't work with django.

Eli_West

unread,
Mar 15, 2012, 2:34:48 AM3/15/12
to Django users
Found that jquery ajax does not load correctly in my firefox install.
Stock jquery example wasnt working either so I ran it in a Windows IE
install.
Reply all
Reply to author
Forward
0 new messages