[Fixed]-Send JSON object back to server in Django

1👍

When you get the result from the LinkedIn, make an ajax call to your Django view from the browser like this:

if(YOU_GOT_THE_RESULT){

    $.ajax({
       url: your_url,
       type: "POST",
       dataType: "json",
       data: JSON_DATA_YOU_GOT_FROM_LINKEDIN,
       statusCode: {
         200: function (your_Response_Data) {
            // YOUR SERVER'S RESPONSE
            // you can act on your server's 
            // response if there will be any
            // eg. you can send back information to update UI. 
          },
          // ... handle errors if required
          404: function () {
             // what to do on 404 etc.
          }
       },
       complete: function (jqXHR, textStatus) {
          // Things to do after everything is completed
       }
    });
}

In your Django view, respond to this ajax request. If your view is only going to respond to ajax requests you can simply check if request.is_ajax(): . This is a post request so your view should respond to posts. Data you’re looking for is inside request.POST.

Good luck.

0👍

When you have a JSON in python (actually a string with JSON format), you can use json library to get it back to a python object: dict or list

>>> import json
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]
👤Gocht

Leave a comment