当我们在浏览器中点击URL URL时,我们获得了数据。我们得到了数据
[{"UserId":"c2fbd9fb-a423-4d33-9ea4-3aa58f7b52cf","UserType":"Parent","OutPutMessage":"Sucess"}].
但是我们需要通过ajax调用来获取数据。我们尝试过这样的
window.onload = function (){
$.ajax({
url:'http://janasenanews.com/MyService.asmx/GetUserLoginVerification',
data: {
username:"9440325333",
password :"9440325333"
},
type: "GET",
dataType: 'JSON',
success:function(data) {
alert( data);
//console.log("Here is the data", data);
}
});
}
但我们有两个错误
Failed to load resource: the server responded with a status of 500 (Internal Server
XMLHttpRequest cannot load Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.
请告诉我们我们的代码中有什么问题。
答案 0 :(得分:0)
使用以下命令更改脚本:
window.onload = function (){
$.ajax({
url:'http://janasenanews.com/MyService.asmx/GetUserLoginVerification',
data: {
username:"9440325333",
password :"9440325333"
},
type: "GET",
dataType: 'JSON',
success:function(data) {
alert( data);
//console.log("Here is the data", data);
}
});
}
答案 1 :(得分:0)
从您问题的标签看起来您正在从Cordova应用程序发出ajax请求?如果是这样,您需要将Cordova白名单插件添加到您的应用中:
config.xml
然后在您的<access>
中,您需要为您的网络服务添加<access origin="http://janasenanews.com" />
标记:
<access origin="*" />
或允许所有请求:
index.html
在Android上,您还需要向<meta http-equiv="Content-Security-Policy" content="default-src 'self' janasenanews.com">
添加内容安全政策(CSP):
%d
有关所有这些的更多信息,请访问:https://github.com/apache/cordova-plugin-whitelist