我想要这样的东西:How to use Basic Auth with jQuery and AJAX?
在那里他们解释了如何使用身份验证
我需要使用jQuery $.getJSON
而不是$.ajax
请求到服务器,因为它不支持跨站点。而且我还需要提交用户和密码。有没有办法在$.getJSON
中提交用户和密码作为参数而无需像https://user:[email protected]
那样在网址中发送?
$ .getJSON是$ .ajax的简写,所以你可能确实需要ajax。你可以在http://api.jquery.com/jquery.ajax/上看到如何设置标题
$.ajax(url, {crossDomain:true, headers:{'X-My':'Foo'}})
$.getJSON("url", { user: "name", password: "123456" })
.done(function(json) {
console.log("Store User autthentication successfully");
})
.fail(function(jqxhr, textStatus, error) {
});