A站(www.a.com),有個(gè)form表單,ajax提交到 B站(www.b.com),還附帶個(gè)驗(yàn)證碼
A站上的表單代碼如下
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></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跨域提交需要www.lol9.cn六久閣 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> <div onclick="send()">提交</div> </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,
B站上的 /plus/diy.php 文件上面加入
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)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)ajax跨域提交自定義表單和跨域驗(yàn)證代碼問題解決