Cross domain POST query using Cross-Origin Resource Sharing getting no data back

后端 未结 4 1308
独厮守ぢ
独厮守ぢ 2020-12-08 12:09

I\'m sending data cross domain via a POST request but the response isn\'t working, specifically, jQuery\'s success handler never gets called.

Stuff being used: Djang

4条回答
  •  伪装坚强ぢ
    2020-12-08 13:03

    REQUEST:

     $.ajax({
                url: "http://localhost:8079/students/add/",
                type: "POST",
                crossDomain: true,
                data: JSON.stringify(somejson),
                dataType: "json",
                success: function (response) {
                    var resp = JSON.parse(response)
                    alert(resp.status);
                },
                error: function (xhr, status) {
                    alert("error");
                }
            });
    

    RESPONSE:

    response = HttpResponse(json.dumps('{"status" : "success"}'))
    response.__setitem__("Content-type", "application/json")
    response.__setitem__("Access-Control-Allow-Origin", "*")
    
    return response
    

提交回复
热议问题