[英]How to post a body in in java script and ajax to API
I have some existing code which is run in a MS outlook plugin which authenticates with a backend.我有一些现有代码在 MS Outlook 插件中运行,该插件通过后端进行身份验证。 I need to update the code to send the user and password as part of body in json doc since we are having issues with users using special char like # etc n the password.我需要更新代码以将用户和密码作为 json doc 正文的一部分发送,因为我们遇到了使用特殊字符(如 # 等 n 密码)的用户的问题。
function authenticate(host, userid ,password, callback) {
//replace server url
var requestUrl
if (host){
requestUrl = "https://" + host + "/auth/plugin/" + userid + "/" + password
}else{
requestUrl = "https://127.0.0.1/auth/plugin2/" + userid + "/" + password
}
$.ajax({
type: "POST",
url: requestUrl,
body: {userid: "user", password : "myPassword"},
cache:false
}).done(function(res){
callback(res);
}).fail(function(error){
callback(null, error);
});
}
i tried the body tag but i don't see anything in my backend that there was a body sent我尝试了 body 标签,但我在后端没有看到任何发送了 body 的内容
你可以试试data: {userid: "user", password : "myPassword"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.