DJANGo Ajax请求有时返回响应,并且有时发生错误

时间:2018-09-05 09:46:23

标签: python ajax django

错误::

  

jquery.min.js:2 POST http://127.0.0.1:9000/xyz/test 0()

path('test', views.test,name="test")

def test(request):
    json_data= json.dumps({"query_id":"213"})
    return HttpResponse(json_data, content_type='application/json')

function call_ajax(){
    $.post({
        url: "{%url 'home:test'%}",
        data: {
          'csrfmiddlewaretoken': '{{ csrf_token }}'
        },
        success: function (data) {
            console.log(data.query_id);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.responseText);
        }
    });
}

0 个答案:

没有答案