Ajax POST请求在Djang中失败

2024-09-30 18:33:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在发出一个Ajax POST请求,但在我的视图中它没有被识别出来。在

代码输入视图.py公司名称:

^{1}$

我的中间件设置是:

^{pr2}$

我的javascript函数是:

function submitForm()

{

    //document.forms["myForm"].submit();

    xhrPost = getXhrObject();
    var arrFiles = document.getElementById('id_file');
    var fileToUpload = arrFiles.files[0];
    xhrPost.onreadystatechange = function() {
        if(xhrPost.readyState == 4 && xhrPost.status == 200)
            document.getElementById("upload-progress-bar").innerHTML = xhrPost.responseText;
        else
            document.getElementById("upload-progress-bar").innerHTML = "processing upload...";
    }

    xhrPost.open("POST","/upload.psp/",true);

    var boundary = "AJAX--------------" + (new Date).getTime();
    var contentType = "multipart/form-data; boundary=" + boundary;
        xhrPost.setRequestHeader("Content-Type", contentType);
    xhrPost.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));

    xhrPost.send(fileToUpload);

    return false;

}

谁能告诉我我缺少什么吗?为什么在我的“上传”功能里,请求没有被重新编码为“POST”views.py?在

提前谢谢。在


Tags: py视图varbarfunctionpostdocumentupload