你瞧,你绿油油的小草从土里钻了出来。嫩嫩的,它在饱受严冬的考验之后,在严冬它聚集着力量,想在春天到来时,将力量释放出来,它展示出了生命力的顽强,也展现出自己对春天的渴望!在万物最需要水的时候,春雨悄悄地轻轻地到来了。生怕踩到了这些顽强的小精西。春雨打在小草的脸上,轻轻地。小草贪婪的吮吸着春雨,一会儿,春风也来 "凑热闹 "了,春风来为柳树 "梳头 "来了,春风也轻轻地,怕自己的鲁莽把柳树的头发弄断了。
A站(www.a.com),有个form表单,ajax提交到 B站(www.b.com),还附带个验证码。
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跨域提交需要
success: function(data){
if(data=="success"){
alert('发送成功!');
}else{
alert('发送失败!');
}
}
});
}
</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>
验证码:
<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、验证码 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");
到此这篇关于织梦javascript ajax跨域提交自定义表单就介绍到这了。在心甘情愿的浪费的过程里,青春渐渐逝去,直到消失,而我们却继续着在青春上所遗留的习惯却不自知。不知道我们在重复着浪费的举动,也不知道自己其实要给青春交出答卷,更不知道要用何种方式去祭奠青春。更多相关织梦javascript ajax跨域提交自定义表单内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!