Adam Starrh Adam Starrh - 6 months ago 19
jQuery Question

Django/Ajax Get "data" returning html from firing page instead of target view

I'm using the following simple AJAX call.

url: $('#currentNodes').attr('target'),
type: 'get',
dataType: "html",
success: function(data) {
failure: function(data) {

It is supposed to grab the target from the following element:

<p><a href="{% url "current_nodes" view.slug %}" id="currentNodes">Test</a></p>

When I click on the above element, my browser displays the HTML I set up in my

def current_nodes(request, slug):
html = "<html><body>Smoke Test for {}</body></html>".format(slug)
return HttpResponse(html)

at the url defined in my

url(r'^(?P<slug>[a-zA-Z0-9-]+)/current_nodes/$', current_nodes, name="current_nodes"),

But according to
, the Ajax call from this link receives the response that comes from the view that is serving the current page, not the one that I ask for in the target. Sure enough, if I try to do anything with it, it displays the full html of the template I am on, rather than plugging in the html I'm trying to process.

What am I missing?


#currentNodes is an a element. It doesn't have a target attribute; it has an href.

url: $('#currentNodes').attr('href'),