打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Jquery Cross
Jquery Cross-Domain ajax call using JSONP
ASP.NET Community, 11 Oct 2013
5.00 (1 vote)
Rate this:
Hi everyone. We all know the role of ajax and its implementation. We can use ajax in asp.net as well as in javascript/jquery. But there is a
Editorial Note
This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.
Hi everyone. We all know the role of ajax and its implementation. We can use ajax in asp.net as well as in javascript/jquery. But there is a limitation of same origin policy. i.e. we can only use ajax to post and get requests within our site. We can call webservices but that is from the code behind only. Even if we use any scripting language it restricts us calling a third party domain. Also over SSL javascript/jquery's ajax call gives up easily. But using jsonp with jquery's ajax api call we can target the ajax call outside the scope of our website.
$(document).ready(function() {
var surl = "http://www.anotherdomain.com/webservice.asmx";
$.ajax({
type: 'GET',
url: surl,
crossDomain: true,
contentType: "application/json; charset=utf-8",
data: { UserID: 1234 },
dataType: "jsonp",
success: function(msg) {
$.each(msg, function(name, value) {
alert(value);
});
},
error: function(xhr, status, error) { alert('Servidor de error 404 !!'); },
async: false,
cache: false
});
});
Note:- This will only work with json data type, so while requesting a web service should return the data in Javascript Object notation format.
License
This article, along with any associated source code and files, is licensed underThe Code Project Open License (CPOL)
Share
email
twitter
facebook
linkedin
reddit
google+
pinterest
About the Author
ASP.NET Community
United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community. Group type: Collaborative Group
247 members
Article Top
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jquery ajax请求 发生canceled状态时的处理
Jquery+Ajax按钮点击显示等待图片
ASP.NET MVC中使用AJAX(XMLHttpRequest、Microsoft A...
传智播客.Net培训.net视频教程
.net技术整理
应用最广的十大Javascript框架
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服