Ajax request not receiving xml from Django

Posted by amougeot on Stack Overflow See other posts from Stack Overflow or by amougeot
Published on 2010-01-16T23:57:23Z Indexed on 2010/06/09 22:02 UTC
Read the original article Hit count: 230

Filed under:
|
|
|

I have a Django server which handles requests to a URL which will return some HTML for use in an image gallery. I can navigate to the URL and the browser will display the HTML that is returned, but I can't get that same HTML by doing an AJAX call (using jQuery) to the same URL.

This is the view that generates the response:

def gallery_images(request, gallery_name):
    return render_to_response('galleryimages.html', {'images': get_images_of_gallery(gallery_name)}, mimetype='text/xml')

This is the 'galleryimages.html' template:

{% for image in images %}
<div id="{{image.name}}big">
    <div class="actualImage" style="background-image:url({{image.image.name}});">
        <h1>{{image.caption|safe}}</h1>
    </div>
</div>
{% endfor %}

This is the jQuery call I am making:

$("#allImages").load("http://localhost:8000/galleryimages/Web");

However, this loads nothing into my #allImages div. I've used firebug and ran jQuery's Ajax method .get("http://localhost:8000/galleryimages/Web") and firebug says that the response text is completely empty.

When I check my Django server log, this is the entry I see for when I navigate to the URL manually, through my browser:

[16/Jan/2010 17:34:10] "GET /galleryimages/Web HTTP/1.1" 200 215

This is the entry in the server log for when I make the AJAX call:

[16/Jan/2010 17:36:19] "OPTIONS /galleryimages/Web HTTP/1.1" 200 215

Why does the AJAX request not get the xml that my Django page is serving?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX