ASP跨域调用Webservices方法
仅用于记录与分享,直接贴代码:
<script type="text/javascript"> function check(){ var title=$('#title').val(); var pic=$('#pic').val(); var detail=$('#detail').val(); var det=$('#det').val(); var type_sort=$('#sort').val(); if(title=="" || pic=="" || detail=="" || type_sort=="") {alert("相关字段不能为空,请检查确认后再提交!");return false;} return true; } </script> <form name="form1" action="" method="post" onsubmit="javascript:return check()"> <p align="center"><input type="submit" onClick="action='test.asp?act=add'" value="新增"><input type="hidden" name="id" value=""><input type="button" value="关闭" onClick="colos_div();"></p> <table width="100%" border="0"> <tr><td align="center" width="10%">标题</td><td> <input type="text" id="title" name="strmodel_title"></td></tr> <tr><td align="center">图片</td><td> <input type="text" id="pic" name="strmodel_logo"></td></tr> <tr><td align="center">描述</td><td> <input type="text" id="detail" name="strmodel_desc"></td></tr> <tr><td align="center">排序</td><td> <input type="text" id="sort" name="strsorting"></td></tr> <tr><td align="center">发布</td><td> <input type="checkbox" id="isdel" name="strisdel"> 打勾为发布</td></tr> <tr><td align="center">详细内容</td><td> <!--<textarea style="width:1000px;height:300px" id="det" name="strmodel_detail"></textarea>--> <script id="editor" type="text/plain" style="width:1000px;height:200px;" name="strmodel_detail"></script> </td></tr> <!--<tr><td colspan="2" align="center"><input type="submit" onClick="action='test.asp?act=add'" value="新增"><input type="hidden" name="id" value=""><input type="button" value="关闭" onClick="colos_div();"></td></tr>--> </table> </form> <% if request.Form<>"" then dim act act=request.QueryString("act") dim strbrandid,strmodelid,strmodel_title,strmodel_logo,strmodel_desc,strmodel_detail,strsorting,strisdel strbrandid=1 strmodelid=request.Form("id") strmodel_title=request.Form("strmodel_title") strmodel_logo=request.Form("strmodel_logo") strmodel_desc=request.Form("strmodel_desc") strmodel_detail=request.Form("strmodel_detail") strsorting=request.Form("strsorting") strisdel=1 if request.Form("strisdel")="on" then strisdel=0 end if dim url,soaprequest,retvalue if act="add" then url="http://10.10.1.10/webservices/test.asmx/add" '下面是webservice的参数 soaprequest="strbrandid=" & strbrandid & "&strmodel_title=" & strmodel_title & "&strmodel_logo=" & strmodel_logo & "&strmodel_desc=" & strmodel_desc& "&strmodel_detail="&strmodel_detail& "&strsorting="&strsorting& "&strisdel="&strisdel Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP") xmlhttp.Open "POST",url,false xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.setRequestHeader "HOST","10.10.1.10" xmlhttp.setRequestHeader "Content-Length",LEN(soaprequest) xmlhttp.Send(soaprequest) if xmlhttp.Status = "200" then response.Write("<script language='javascript'>alert('添加成功!');location.href='test.asp';</script>") else response.Write("<script language='javascript'>alert('添加失败!\n可能服务器连接故障,请稍后重试!');location.href='test.asp';</script>") end if end if if act="modi" then url="http://10.10.1.10webservices/test.asmx/modi" '下面是webservice的参数 soaprequest="strbrandid=" & strbrandid & "&strmodelid=" & strmodelid & "&strmodel_title=" & strmodel_title & "&strmodel_logo=" & strmodel_logo & "&strmodel_desc=" & strmodel_desc& "&strmodel_detail="&strmodel_detail& "&strsorting="&strsorting& "&strisdel="&strisdel 'response.Write("<script language='javascript'>alert('"&soaprequest&"')</script>") Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP") xmlhttp.Open "POST",url,false xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.setRequestHeader "HOST","10.10.1.10" xmlhttp.setRequestHeader "Content-Length",LEN(soaprequest) xmlhttp.Send(soaprequest) 'Response.Write xmlhttp.Status &"<br>" 'Response.Write xmlhttp.StatusText &"<br>" 'response.Write xmlhttp.responseText 'Set xmlhttp = Nothing if xmlhttp.Status = "200" then response.Write("<script language='javascript'>alert('修改成功!');location.href='test.asp';</script>") else response.Write("<script language='javascript'>alert('修改失败!\n可能服务器连接故障,请稍后重试!');location.href='test.asp';</script>") end if end if end if %>
博客地址:http://www.cnblogs.com/colinliu/
博客版权:本文以学习、记录、分享为目的。欢迎大家转载,但务必注明原文地址,谢谢合作!
博客版权:本文以学习、记录、分享为目的。欢迎大家转载,但务必注明原文地址,谢谢合作!