当前位置:编程学习 > JS >>

jquery异步提交与跨域提交表单方法

文章下面来提供一下关于post提交方式结合form表单的submit调用ajax的回调函数利用script 的跨域访问特性,结合form表单的数据格式化,所以只能采用get方式提交,为了安全,浏览器是不支持post跨域提交的。 2.采用jsonp跨域提交表单是比较好的解决方案。
3.也可以动态程序做一代理。用代理中转跨域请求

 

jquery(function($) {
// 使用 jquery 异步提交表单
$('#f1').submit(function() {
$.ajax({
url: 'ta.asp教程x',
data: $('#f1').serialize(),
type: "post",
cache : false,
success: function(data)
{alert(data);}
});
return false;
});
});

jquery json   jquery 异步跨域提交表单

<script>
jquery(function($)
{
// 使用 jquery 异步跨域提交表单
$('#f1').submit(function()
{
$.getjson("ta.aspx?"+$('#f1').serialize()+"&jsoncallback=?",
function(data)
{
alert(data);
});
return false;
});
});


</script>

html代码

<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>

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,