惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - Xt Idt

ASP.NET MVC 4 RC的JS/CSS打包压缩功能 自定义WCF的配置文件 C#综合揭秘——分部类和分部方法 结合领域驱动设计的SOA分布式软件架构 SOA面向服务架构——SOA的概念 使用WCF实现SOA面向服务编程—— 架构设计 选择HttpHandler还是HttpModule? MVP解读 揭秘Amazon反应速度超快的下拉菜单 jQuery-menu-aim.js SQL注入攻防入门详解 Visual Studio 2010 如何改用 Beyond Compare 作为 TFS 的比较工具 使用HttpContext的User属性来实现用户验证-.NET教程 在Web Service中使用Windows验证的方式 对于表列数据类型选择的一点思考 (转发)有关T-SQL的10个好习惯 jQuery.extend 函数详解 跟我一起学写jQuery插件(附完整实例及下载) 分析URL Routing和URL Rewriting两者之间的不同
jquery post get 跨域 提交数据
Xt Idt · 2012-11-29 · via 博客园 - Xt Idt

[转载 jquery post 跨域 提交数据

2011-06-28 11:10

跨域的N种形式:

1.直接用jquery中$.getJSON进行跨域提交

          优点:有返回值,可直接跨域;

          缺点:数据量小

   提交方式:仅get (无$.postJSON)

2.在页面中嵌入一个iframe,把iframe的宽和高设置为0进行跨域提交

           优点:可直接跨域;

           缺点:无返回值(脱离ajax本质);

    提交方式:get/post

3.直接用$.post跨域,先提交到本地域名下一个代理程序,通过代理程序向目的域名进行post或get提交,并根据目的域名的返回值通过代理 程序返回给本地页面

          优点:有返回值,可直接跨域,可通过 代理程序 统计ip等用户信息,增加安全性;

   提交方式:get/post

       复杂度:需要前端工程师和后端工程师配合(php/java../工程师)  

           缺点:需要消耗本地服务器资源,增加ajax等待时间(可忽略)

4.向百度学习的思路:由于调用任何js文件不涉及跨域问题,所以js脚本中可以编写调用远程服务器上的js文件,该文件实现你需要的业务。

                                  即a.js动态调用www.baidu.com/b.js ,其中b.js实现业务

5.待研究......


1.使用post提交方式

2.构造表单的数格式

3.结合form表单的submit调用ajax的回调函数。

代码:

使用 jQuery 异步提交表单

复制代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<script src="js/jquery-1.4.2.js"></script>
<script>
jQuery(
function($) {
// 使用 jQuery 异步提交表单
$('#f1').submit(function() {
$.ajax({
url:
'ta.aspx',
data: $(
'#f1').serialize(),
type:
"post",
cache :
false,
success:
function(data)
{alert(data);}
});
return false;
});
});
</script>
<body>
<form id="f1" name="f1">
<input name="a1" />
<input name="a2" />
<input id="File1" type="file" name="File1"/>
<input id="Submit1" type="submit" value="submit" />
</form>
</body>
</html>

复制代码

如何异步跨域提交表单呢?

1.利用script 的跨域访问特性,结合form表单的数据格式化,所以只能采用get方式提交,为了安全,浏览器是不支持post跨域提交的。

2.采用JSONP跨域提交表单是比较好的解决方案。

3.也可以动态程序做一代理。用代理中转跨域请求。

 代码:

使用 jQuery 异步跨域提交表单

复制代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<script src="js/jquery-1.4.2.js"></script>
<script>
jQuery(
function($)
{
// 使用 jQuery 异步跨域提交表单
$('#f1').submit(function()
{
$.getJSON(
"ta.aspx?"+$('#f1').serialize()+"&jsoncallback=?",
function(data)
{
alert(data);
});
return false;
});
});
</script>
<body>
<form id="f1" name="f1">
<input name="a1" />
<input name="a2" />
<input id="File1" type="file" name="File1"/>
<input id="Submit1" type="submit" value="submit" />
</form>
</body>
</html>

复制代码

补充:方法1不能实现跨越提交。

注意:输出json格式{'a1','a1value','a2':'a2value'}

字符必须用引号包住,数字可以不加引号。如:{'a1',10,'a2':20}

posted on 2012-11-29 15:14  Xt Idt  阅读(658)  评论()    收藏  举报