[英]showing 400 (Bad Request) in ajax
我正在使用cordova,在執行json時出現錯誤“無法加載資源:服務器響應狀態為400(錯誤請求) ”。
但是當我在郵遞員上運行相同的代碼時得到了正確的答案。請幫我解決這個問題。 代碼是:
$.ajax({
url: url,
type: "POST",
async: false,
ContentType: "application/json; charset=utf-8",
data: jData,
dataType: "json",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
},
});
並附上郵遞員上正確答案的截圖,供大家參考
您需要對正在發送的 JSON 數據進行字符串化
$.ajax({
type: 'POST',
url: url,
async: false,
data: JSON.stringify(jData),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
嘗試刪除 jData 周圍的左括號和右括號
var jData = {};
不是
var jData = [{}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.