[英]Posting raw data to a WebAPI using JQuery and AJAX
I am trying to work out how to post raw data to a webAPI using JQuery and Ajax, but I cannot seem to get the data to be sent across. 我正在尝试找出如何使用JQuery和Ajax将原始数据发布到webAPI,但是我似乎无法获取要发送的数据。
The endpoint works in Postman: 端点在Postman中工作:
Here is my rather simple JQuery: 这是我相当简单的JQuery:
$.ajax({type: "POST", url: myUrl, data: ["21924"]});
What am I missing? 我想念什么? This is not my usual area so I've had a good look through other questions, but non seem to quite fit!
这不是我通常的工作范围,因此我在其他问题上看上去很好,但似乎不太合适! How do I recreate this Postman call via JQuery and Ajax?
如何通过JQuery和Ajax重新创建此邮递员呼叫?
Thanks. 谢谢。
Try specifying the data type and stringifying your data, like this: 尝试指定数据类型并对数据进行字符串化,如下所示:
$.ajax({
type: "POST",
url: myUrl,
data: JSON.stringify(["21924"]),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){console.log(data);},
failure: function(errMsg) {console.log(errMsg);}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.