JQuery $ .getJSON用户名和密码基本身份验证?

问题描述 投票:2回答:2

我想要这样的东西:How to use Basic Auth with jQuery and AJAX?

在那里他们解释了如何使用身份验证

我需要使用jQuery $.getJSON而不是$.ajax请求到服务器,因为它不支持跨站点。而且我还需要提交用户和密码。有没有办法在$.getJSON中提交用户和密码作为参数而无需像https://user:[email protected]那样在网址中发送?

javascript jquery ajax getjson
2个回答
0
投票

$ .getJSON是$ .ajax的简写,所以你可能确实需要ajax。你可以在http://api.jquery.com/jquery.ajax/上看到如何设置标题

$.ajax(url, {crossDomain:true, headers:{'X-My':'Foo'}})

这可能是Pass request headers in a jQuery AJAX GET call的重复


0
投票
$.getJSON("url", { user: "name", password: "123456" })
    .done(function(json) {
        console.log("Store User autthentication successfully");
    })
    .fail(function(jqxhr, textStatus, error) {
    });
© www.soinside.com 2019 - 2024. All rights reserved.