javascript - JSON response from Python json.dumps -


i trying send django httpresponse encoded json javascript.

python:

response_data = {} response_data['status'] = 'incomplete' return httpresponse(json.dumps(response_data), content_type="application/json") 

jquery:

function auth_request(){   $.ajax({     url: auth_endpoint + "myid0001",     context: document.body,     success: function(response){        console.log(response);       console.log(response.status);       if(response.status == "incomplete"){         //do here       }      }   }  }); } 

the console prints {"status": "incomplete"} first console log , undefined console.log function accessing status element.

i tried using json.parse(response) error

uncaught syntaxerror: unexpected token a in jquery.js file believe indicating object json object. however, if check type of object, displays string. how can access elements of response json object?

you need parse json js object when it's received. otherwise, it's text.

jquery if specify datatype: "json" in ajax call.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -