SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    0 Post(s)
    0 Thread(s)

    Send httpresponse to client

    Hi all,
    new here

    i have this python function
    Code Python:
    def gtest(request):
        p = request.POST
        print p
        g = p['information']
        print g
        to_json = {
            "key1": "value1",
            "key2": "value2"
       jsonValidateReturn = simplejson.dumps({"jsonValidateReturn": "ddddd"})
        return HttpResponse(jsonValidateReturn, content_type='application/json' ,mimetype='application/json')

    and on the client side
    Code Javascript:
            url: "",
            type: "POST",
            data: { information : "You have a very nice website, sir."},
            dataType: "json",
            success: function(data) {
            	alert ("post is success");
            error: function(request,error) 

    no matter what i do when the post is back it goes to error.
    on my server i see this message
    "POST /api/gtest/ HTTP/1.1" 200 31
    so it looks like response should work but no matter what it does not go to the success function..

    plz help :\

    Last edited by Mittineague; Feb 10, 2013 at 15:54. Reason: reformatting bbcode tags

  2. #2
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    51 Post(s)
    2 Thread(s)
    Could you send a message to a moderator (anyone whose name is green or blue) and ask to have your code edited? Or post again, but wrap your code in code tags ([code] to start, close it with [/code]). Otherwise the forums eat up your indentation which with Python we need. :)

    Also: Python 2x or 3x? Are you using httplib?

    return HttpResponse(jsonValidateReturn, content_type='application/json' ,mimetype='application/json')
    What are the required arguments for this (I see a different list on the library pages at for version 2)? I ask because MIMEtype should be represented by Content Type as far as the browser is concerned.

    When you run your Javascript, in your browser debugger, can you see anything else being returned? What errors are being checked in the
    success: function(data) {
    alert ("post is success");
    error: function(request,error)

    section? Those success and errors should refer to the ajax readyStates I think.
    You may not be getting a readyState 4. Here are the states, and you should be able to see which one you get in your browser debugger as you step through your Javascript.

    Quote Originally Posted by ibm article
    0: The request is uninitialized (before you've called open()).
    1: The request is set up, but not sent (before you've called send()).
    2: The request was sent and is in process (you can usually get content headers from the response at this point).
    3: The request is in process; often some partial data is available from the response, but the server isn't finished with its response.
    4: The response is complete; you can get the server's response and use it.
    Also back when I was doing ajax by hand I needed to add in a send() call just to make Opera happy, and I dunno if Opera fixed this or if jQuery (is that what you're using) already fixes this.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts