大家好,
你能帮我解决一些问题吗?我需要为我的应用程序使用一些 API。首先,我需要登录服务器。
我尝试这样做,使用 ajax post 请求 EXAMPLE :
$.ajax({
url: 'http://apps.dhis2.org/demo/dhis-web-commons-security/login.action',
type: 'POST',
data: {
j_username: 'admin',
j_password: 'district'
},
success: function(data) {
alert('Success!!!');
},
error: function() {
alert('Fail!');
}
});
但此示例仅在我从具有与服务器相同域 的应用程序调用此帖子时才有效。那么如何从外部应用运行它呢?
谢谢
最佳答案
首先,您需要确保您的后端能够处理 CORS(跨源资源共享)或跨域请求。 在您的 ajax 代码中添加此属性“crossDomain:true”。
关于javascript - 从外部应用程序到 Spring Security 的 Ajax 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16856365/