Note that there are some explanatory texts on larger screens.

plurals
  1. POinternal server eroor 500 django when using simplejson.loads(request.raw_post_data)
    primarykey
    data
    text
    <p>I'm trying to receive a json object from my jquery client but when I call the simplejson.loads(request.raw_post_data) I get internal server error 500. The server receives the call since I'm getting the callback fro the server when the simplejson.loads(request.raw_post_data) line is commented. But as soon as I uncomment that line the error is thrown.</p> <p>ajaxtest.html</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("#post").click(function(){ var test = new Object(); test.name = "Kalle"; test.pw = "kula"; $.ajax({ url: "ajaxtest/", type: 'POST', dataType: 'json', data: {client_response: JSON.stringify(test), csrfmiddlewaretoken: '{{ csrf_token}}'}, success: function(result) { alert(result); } }); }); }); &lt;/script&gt; </code></pre> <p> </p> <p>views.py </p> <pre><code>from django.shortcuts import render from django.shortcuts import render_to_response from django.template import RequestContext from django.http import HttpResponse from django.utils import simplejson from manges.models import User # Create your views here. def ajax_test(request): print 'Hej' if request.method == 'GET': print 'GET' c = User.objects.get(pk=1) print c.emailadress print c.password return HttpResponse(simplejson.dumps(c, default=User.serializable)) if request.method == 'POST': print 'POST' data = simplejson.load(request.raw_post_data) print json_data.name return HttpResponse(simplejson.dumps('Got JSON!')) def start_page(request): print 'Start' return render_to_response('ajaxtest.html', context_instance=RequestContext(request)) </code></pre> <p>urls.py</p> <pre><code>from django.conf.urls import patterns, include, url from manges.views import ajax_test, start_page from django.contrib import admin admin.autodiscover() urlpatterns = patterns('manges.views', url(r'^$', start_page), url(r'^ajaxtest/$', ajax_test), # Examples: # url(r'^$', 'myforum.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), ) </code></pre> <p>Any ideas??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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