A站(www.a.com),有個(gè)form表單,ajax提交到 B站(www.b.com),還附帶個(gè)驗(yàn)證碼
<script type="text/javascript" src="/uploads/allimg/200915/1534551D1-0.jpg"></script>
<script>
function send(){
$.ajax({
cache:true,
type:"POST",
url:"http://www.b.com/plus/diy.php",
data:$('#diyform').serialize(),
xhrFields:{withCredentials: true}, //ajax跨域提交需要
crossDomain:true, //ajax跨域提交需要
success: function(data){
if(data=="success"){
alert('發(fā)送成功!');
}else{
alert('發(fā)送失敗!');
}
}
});
}
</script>
<form action="" enctype="multipart/form-data" method="post" id="diyform">
<input type="hidden" name="action" value="post" />
<input type="hidden" name="diyid" value="2" />
<input type="hidden" name="do" value="2" />
<input type="hidden" name="dede_fields" value="name,text" />
<input type="hidden" name="dede_fieldshash" value="c2be5bb5ec45d9d01ca9f60dc469b3fb" />
<p>
姓名:
<input type='text' name='name' id='name' />
</p>
<p>
驗(yàn)證碼:
<input type="text" name="validate"><img src="http://www.b.com/include/vdimgck.php" align="absmiddle" onclick="this.src='http://www.b.com/include/vdimgck.php?tag='+Math.random();" style="cursor:pointer;">
</p>
<p onclick="send()">提交</p>
</form>
1、提交到 http://www.b.com/plus/diy.php
2、驗(yàn)證碼 http://www.b.com/include/vdimgck.php
3、ajax 跨域必需js代碼
xhrFields:{withCredentials: true},crossDomain:true,
header("Access-Control-Allow-Credentials:true");
header("Access-Control-Allow-Origin:http://www.a.com");
這就完成了。
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: 織夢ajax跨域提交自定義表單和跨域驗(yàn)證碼問題