欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery下異步提交表單 異步跨域提交表單

 更新時間:2010年11月17日 14:09:31   作者:  
基于jquery的實現(xiàn)異步跨域提交表單的實現(xiàn)代碼,需要的朋友可以參考下。
1.使用post提交方式
2.構(gòu)造表單的數(shù)格式
3.結(jié)合form表單的submit調(diào)用ajax的回調(diào)函數(shù)。
使用 jQuery 異步提交表單代碼:
復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>無標(biāo)題頁</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 的跨域訪問特性,結(jié)合form表單的數(shù)據(jù)格式化,所以只能采用get方式提交,為了安全,瀏覽器是不支持post跨域提交的。
2.采用JSONP跨域提交表單是比較好的解決方案。
3.也可以動態(tài)程序做一代理。用代理中轉(zhuǎn)跨域請求。
使用 jQuery 異步跨域提交表單代碼:
復(fù)制代碼 代碼如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>無標(biāo)題頁</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>

相關(guān)文章

最新評論