ajax GET无法工作(服务数据无法获取)
ajax GET Not working (Service Data not getting)
当我们在浏览器中点击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.
请指导我们代码中的错误。
使用更改脚本
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);
}
});
}
从你问题上的标签来看,你似乎是在从Cordova应用程序发出ajax请求?如果是这样,您需要将Cordova白名单插件添加到您的应用程序中:
cordova plugin add cordova-plugin-witelist
然后在您的config.xml
中,您需要为您的web服务添加一个<access>
标签:
<access origin="http://janasenanews.com" />
或允许所有请求:
<access origin="*" />
在Android上,您还需要在index.html
:中添加内容安全策略(CSP)
<meta http-equiv="Content-Security-Policy" content="default-src 'self' janasenanews.com">
关于这一切的更多信息,请点击此处:https://github.com/apache/cordova-plugin-whitelist
相关文章:
- 使用jquery将mysql数据获取到新的表行中
- 使用createContainer将Meteor数据获取到React Native中时出现问题
- 创建按钮,根据表单字段中的数据获取特定的URL
- 将JSON API数据获取到html
- 将json数据获取到数组中
- 如何将具有多个标签的多个的所有数据获取到一个数组中
- 将状态的 URL 数据获取到模板中
- 如何在jquery中将xml解析数据获取为全局变量
- 在没有JQuery的情况下将JSON数据获取到TVML项目中
- Angular js如何将索引数据获取到另一个模板中
- 如何将PHP Post数据获取到jquery ajax请求中
- 使用javascript中.data()中存储的数据获取变量
- 无法将动态数据获取到 Jquery 饼图中
- 将节点.js neDB 数据获取到变量中
- 更新页面 JSON 数据获取下拉更改
- 将数据绑定到 kendo 下拉列表时,如何将 ajax 响应数据获取到变量
- 画布图像数据获取的值不超过 102,000 个
- 如何通过 JQuery JSON 数据获取 CheckBox(@Html.CheckBox) 的值
- 从html到jquery再到php,再从php到jquery到html,将数据传递到php文件并将数据获取到php文件中
- 如何将Jquery.get中的数据获取到Javascript中的一个变量中