[英]Cross Domain AJAX POST / HTTPS / Header Authentication?
I have to issues: 我要发出的问题:
1) I've tried using JsonP, but can't get POSTing to work. 1)我尝试使用JsonP,但无法使POST正常工作。 Essentially, I'm trying to authenticate with an API, passing a Base64-encoded namevaluepair in the header over HTTPS.
本质上,我试图通过API进行身份验证,并通过HTTPS在标头中传递Base64编码的名称/值对。
2) How do I pass this key/value in the header? 2)如何在标头中传递此键/值? Any help would be appreciated!
任何帮助,将不胜感激! Here is an example of what I want, though this obviously doesn't work:
这是我想要的示例,尽管这显然行不通:
// where does this go?
var headerString = 'user=' + encodeURIComponent(username + ':' + password);
$.ajax({
type: "POST",
url: "https://anotherurl.on.another.server/LOGIN",
data: "I have no data, I'm logging in with header authentication",
dataType: "json",
success: function(data) {
},
error: function(data){
}
});
add headers to ajax call: 将标题添加到ajax调用:
var headerObj = {'user': encodeURIComponent(username + ':' + password)};
$.ajax({
type: "GET",
url: "https://anotherurl.on.another.server/LOGIN",
data: "I have no data, I'm logging in with header authentication",
dataType: "json",
headers: headerObj,
success: function(data) {
},
error: function(data){
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.