Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't post when using ajax in django
    primarykey
    data
    text
    <p>So I've been following this tutorial <a href="http://webcloud.se/log/AJAX-in-Django-with-jQuery/" rel="nofollow">http://webcloud.se/log/AJAX-in-Django-with-jQuery/</a>, and the get method works fine. i.e. I get a popup saying what it should say in the popup. However when I use the post method instead I don't get anything. It appears that the request doesn't even reach my view.</p> <p>This is what my bit of javascript dealing with this looks like:</p> <pre><code>$(document).ready(function(){ $("#popupbutton").click(function(){ $.post("/launch_instances", { name: "Monty", food: "Spam" }, function(data) { alert(data); } ); }); ................... </code></pre> <p>This are the related bit of my template:</p> <pre><code>&lt;center&gt; &lt;div id="popupbutton"&gt;&lt;input type="submit" value="Launch Instances!" /&gt;&lt;/div&gt; &lt;/center&gt; </code></pre> <p>And here is my views.py:</p> <pre><code>from django.http import HttpResponse def li_view(request): return HttpResponse("post gets to the view") if request.is_ajax(): if request.method == 'GET': message = "This is an XHR GET request" elif request.method == 'POST': message = "This is an XHR POST request" else: message = "Nothing" else: message = "No XHR" return HttpResponse(message) </code></pre> <p>As you can see the first thing I do when I get to my view is return a HttpResponse, but when I am using post I don't see any popup like I do when I am using get. So my guess is that for some reason the request doesn't even reach the view.</p> <p>This is what my urls.py:</p> <pre><code>from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^launch_instances/', 'simdata.views.li_view'), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), ) </code></pre> <p>There have been similar questions around but nothing as bizzare as this. I'm new to django/ajax/jquery so probably missing something very small.</p> <p>Thanks in advance :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload