解决Jquery ajax的post get跨域提交表单
2013-05-10 14:35
447 查看
跨域的N种形式:
1.直接用jquery中$.getJSON进行跨域提交
优点:有返回值,可直接跨域;
缺点:数据量小;
提交方式:仅get (无$.postJSON)
[javascript]
view plaincopyprint?
$.getJSON("http://www.sendnet.cn/?callback=?" , { UserId: 1001 },
nction (data) {
alert(data.info);
;
[javascript]
view plaincopyprint?
$.ajax({
type: "Get", or 'POST'
url: "http://www.sendnet.cn/?UserId=1001",
cache: false,
error: function () { },
jsonp: "callback",
dataType: "jsonp",
success: function (result) {
alert(result.info);
}
});
2.在页面中嵌入一个iframe,把iframe的宽和高设置为0进行跨域提交
优点:可直接跨域;
缺点:无返回值(脱离ajax本质);
提交方式:get/post
[plain]
view plaincopyprint?
使用隐藏的iframe来提交表单
1,在页面中嵌入一个iframe,把iframe的宽和高设置为0
2.在iframe的里面里设置一个from的表单,表单的内容就是真正要提交的表单内容。
3.当点击按钮的时候是iframe里的表单提交。
<form id="form2" name="form2" method="post" action="a,jsp" enctype="multipart/form-data">
<input name="option_13412" id="option_13412" type="text"/>
<input name="option_13413" id="option_13413" type="text"/>
<input name="option_13414" id="option_13414" type="text"/>
<input name="option_13415" id="option_13415" type="text"/>
</form>
使用jquery来啊操作iframe中的表单元素
$(window.frames["iframe1"].document).find("#option_13412").val(name);
$(window.frames["iframe1"].document).find("#option_13413").val(phone);
$(window.frames["iframe1"].document).find("#option_13415").val(content);
通过按钮来提交iframe里的表单
$(window.frames["iframe1"].document).find("#form2").submit();
1.直接用jquery中$.getJSON进行跨域提交
优点:有返回值,可直接跨域;
缺点:数据量小;
提交方式:仅get (无$.postJSON)
[javascript]
view plaincopyprint?
$.getJSON("http://www.sendnet.cn/?callback=?" , { UserId: 1001 },
nction (data) {
alert(data.info);
;
$.getJSON("http://www.sendnet.cn/?callback=?" , { UserId: 1001 }, function (data) { alert(data.info); });
[javascript]
view plaincopyprint?
$.ajax({
type: "Get", or 'POST'
url: "http://www.sendnet.cn/?UserId=1001",
cache: false,
error: function () { },
jsonp: "callback",
dataType: "jsonp",
success: function (result) {
alert(result.info);
}
});
我这边试过 get post 都可以
$.ajax({ type: "Get", url: "http://www.sendnet.cn/?UserId=1001", cache: false, error: function () { }, jsonp: "callback", dataType: "jsonp", success: function (result) { alert(result.info); } });
2.在页面中嵌入一个iframe,把iframe的宽和高设置为0进行跨域提交
优点:可直接跨域;
缺点:无返回值(脱离ajax本质);
提交方式:get/post
[plain]
view plaincopyprint?
使用隐藏的iframe来提交表单
1,在页面中嵌入一个iframe,把iframe的宽和高设置为0
2.在iframe的里面里设置一个from的表单,表单的内容就是真正要提交的表单内容。
3.当点击按钮的时候是iframe里的表单提交。
<form id="form2" name="form2" method="post" action="a,jsp" enctype="multipart/form-data">
<input name="option_13412" id="option_13412" type="text"/>
<input name="option_13413" id="option_13413" type="text"/>
<input name="option_13414" id="option_13414" type="text"/>
<input name="option_13415" id="option_13415" type="text"/>
</form>
使用jquery来啊操作iframe中的表单元素
$(window.frames["iframe1"].document).find("#option_13412").val(name);
$(window.frames["iframe1"].document).find("#option_13413").val(phone);
$(window.frames["iframe1"].document).find("#option_13415").val(content);
通过按钮来提交iframe里的表单
$(window.frames["iframe1"].document).find("#form2").submit();
相关文章推荐
- 表单通过get和post方式提交数据解决乱码的方法
- 表单提交方式由POST改为GET出现乱码的解决
- form表单提交的 get/post 方法(二)中文乱码的解决(1)
- Spring MVC 3 表单中文提交post请求和get请求乱码问题的解决方法
- form表单提交的 get/post 方法(二)中文乱码的解决(2)
- 跨域提交时涉及中文编码的解决方案,同时解决post和get方案
- python get,post提交表单
- servlet请求中post提交表单重定向到跨域网站问题
- from 表单提交返回值用post或者是get方法实现
- 表单的提交方式:get和post
- from 表单提交返回值用post或者是get方法实现
- get、post方法提交时的乱码问题解决
- 表单用GET提交数据导致覆盖之前参数的解决办法
- 表单提交 get 与post的区别
- HTML中Form表单提交时,采用 get和post的区别
- Node搭建服务器与GET请求,POST提交表单
- javascript 跨域POST 使用form表单 获取提交返回内容的方法
- Android_HttpClient_get请求post表单提交上传
- 表单提交中Get和Post方式区别
- C#.net模拟提交表单GET、POST