
歡迎訪問(wèn)全國(guó)企業(yè)網(wǎng)站設(shè)計(jì)NO.1網(wǎng)站開(kāi)發(fā)商平臺(tái) | 付款方式 |
POST TIME:2020-10-09
A站(www.a.com),有個(gè)form表單,ajax提交到 B站(www.b.com),還附帶個(gè)驗(yàn)證碼。
<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跨域提交需要 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");
巨號(hào)網(wǎng)網(wǎng)站開(kāi)發(fā)部為全國(guó)企業(yè)提供網(wǎng)頁(yè)設(shè)計(jì)和專業(yè)的公司網(wǎng)站制作等相關(guān)建站服務(wù),并提供24小時(shí)企業(yè)網(wǎng)站設(shè)計(jì)咨詢!
關(guān)于我們 建站知識(shí) 榮譽(yù)資質(zhì)網(wǎng)站地圖