jquery下异步提交表单 异步跨域提交表单
2018-10-12 14:02
344 查看
1.使用post提交方式
2.构造表单的数格式
3.结合form表单的submit调用ajax的回调函数。
使用 jQuery 异步提交表单代码:
如何异步跨域提交表单呢?
1.利用script 的跨域访问特性,结合form表单的数据格式化,所以只能采用get方式提交,为了安全,浏览器是不支持post跨域提交的。
2.采用JSONP跨域提交表单是比较好的解决方案。
3.也可以动态程序做一代理。用代理中转跨域请求。
使用 jQuery 异步跨域提交表单代码:
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>
您可能感兴趣的文章:
相关文章推荐
- 基于jquery的实现异步跨域提交表单的实现代码,需要的朋友可以参考下。
- jquery下异步提交表单 异步跨域提交表单
- jquery表单插件 jquery.form(异步提交)(学习总结)
- Jquery 异步提交表单(post)
- jQuery_表单异步提交
- 使用jQuery.form插件,实现完美的表单异步提交
- 使用jQuery.form插件,实现完美的表单异步提交
- jquery来跨域提交表单
- 使用jquery-form.js实现form表单的异步提交
- 使用jQuery重用form表单并异步提交到其它action
- JQUERY的表单异步提交(ajax)
- 使用jQuery.form插件,实现完美的表单异步提交
- 异步提交表单插件jquery.form.min.js的使用实例
- 使用jQuery.form插件,实现完美的表单异步提交【转发】
- Jquery Jsonp跨域提交表单获取返回数据
- Jquery点击按钮 异步和同步提交表单
- Jquery.Form 异步提交表单
- jquery-jquery异步提交表单插件
- jQuery实现Ajax异步提交表单实现局部刷新
- jQuery异步表单提交