How to set boundary while using XmlHttpRequest and FormData

后端 未结 2 1664
北海茫月
北海茫月 2021-02-06 00:04

I am trying to set the boundary correctly in the header while using FormData to post the XmlHttpRequest:

xhr.open(\"POST\",url);
xhr.setRequestHeader(\"Content-t         


        
2条回答
  •  一个人的身影
    2021-02-06 01:10

    ES method

    Simply don't set the Content-Type header manually and the browser will automatically set "multipart/form-data; boundary=..." value.


    jQuery method

    If you're using jQuery, set contentType option to false:

    $.ajax({
        url: url,
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false
    });
    

提交回复
热议问题