![](/img/trans.png)
[英]POST request works in Postman but gives Bad Request in js code
[英]POST request works in POSTMAN but not in my code JS
我在POSTMAN中嘗試了發帖請求,一切正常。 當我從POSTMAN中將代碼粘貼為Ajax或XRH時,出現了錯誤消息:
- net::ERR_ABORTED 405 (Method Not Allowed) from chrome or firefox
我正在在家中以localhost的身份工作:這是否是特權訪問問題,而我沒有足夠的權限以localhost身份進行POST?
這是我的要求:
var data = new FormData(); data.append("file", file); data.append("backup_date", date); data.append("backed_up_device_name", device); var settings = { "async": true, "crossDomain": true, "url": "url", "method": "POST", "dataType": "jsonp", "headers": { "Content-Type": "application/x-www-form-urlencoded", "cache-control": "no-cache", }, "processData": false, "contentType": false, "mimeType": "multipart/form-data", "data": data } $.ajax(settings).done(function (response) { console.log(response); });
謝謝你的回答
服務器必須在405響應中生成允許標頭字段,其中包含目標資源當前支持的方法的列表。
有關更多信息,請參閱文檔
也就是說,您的服務器不接受對url
的POST請求。 嘗試仔細看一下:
"url": "url", // what is the url? `"url":"ServerURL"`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.