JS实现POST.docx_第1页
JS实现POST.docx_第2页
JS实现POST.docx_第3页
JS实现POST.docx_第4页
JS实现POST.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

function posthtm(url,id,verbs,is)var doc = document.getElementById(id);doc.innerHTML=Loading.;var xmlhttp = false;if(doc!=null)doc.style.visibility=visible;if(doc.style.visibility=visible)xmlhttp=ajax_driv();xmlhttp.open(POST, url,true);xmlhttp.onreadystatechange=function() if (xmlhttp.readyState=4) if (is)doc.innerHTML=xmlhttp.responseText;elseeval(xmlhttp.responseText);xmlhttp.setRequestHeader(Content-Length,verbs.length);xmlhttp.setRequestHeader(CONTENT-TYPE,application/x-www-form-urlencoded);xmlhttp.send(verbs);微软的JavaScript,Post的实例(XMLHTTP) 下面这个functioon是我分析MSN的一个网址截取的,对使用javascript Post数据的时候有用,以前我都是用笨办法在页面上放个隐藏的form然后submit,现在可以直接用使用post了,_!function_sd_Post(Url,Args) varxmlhttp; varerror; eval(tryxmlhttp=newActiveXObject(Microsoft.XMLHTTP);catch(e)xmlhttp=null;error=e;); if(null!=xmlhttp) xmlhttp.Open(POST,Url,false); xmlhttp.setRequestHeader(Content-Type,application/x-www-form-urlencoded); xmlhttp.Send(Args); strText=xmlhttp.responseText; /ifourresponsestartswithhttpthanredirectthere if(strText!=null&strText.toLowerCase().indexOf(http)=0) location.href=strText; else location.href=c_errorUrl; returnstrText; functionGetActionUrl(listKey) returndocument.getElementById(ActionUrl:+listKey).url 靠!下面是从Google搜索到的更有用的,哈哈!/Web/Web_Languages/Q_21132871.html SolutionTitle:Microsoft.XMLHTTPsendingafile askedbymikevandikeon09/15/200404:21PMPDT HiIamcurrentlyre-developingawebbasedfrontendforanestateagenttomanagetheirpropertys.IhavedecidedtouseaMicrosoft.XMLHTTPobjecttocommunicatebetweentheclientandserver.Myproblemisgottodowithsendingafilewiththis.TheclientiscomposedoftheusualGUIcomponentswhichthedatacanbeeasilyretrievedfromforsendingtotheserverbutitalsocontainsafileelementforselectingapictureofthepropertytobeuploaded.HowdoIgetthedatafromthissothatitcanbeuploadedtotheserverusingtheMicrosoft.XMLHTTPobject.IhavefoundabitofcodeonthenetbutitisnousetomebecauseitwouldinvolvechangingthesecurityinInternetOptionswhichIhavenocontrolover. FileSend Ready /filesuploadfunction functionbtn_send.onclick() /createADO-streamObject varado_stream=newActiveXObject(ADODB.Stream); /createXMLdocumentwithdefaultheaderandprimarynode varxml_dom=newActiveXObject(MSXML2.DOMDocument); xml_dom.loadXML(); /specifynamespacesdatatypes xml_dom.documentElement.setAttribute(xmlns:dt,urn:schemas-microsoft-com:datatypes); /createanewnodeandsetbinarycontent varl_node1=xml_dom.createElement(file1); l_node1.dataType=bin.base64; /openstreamobjectandreadsourcefile ado_stream.Type=1;/1=adTypeBinary ado_stream.Open(); ado_stream.LoadFromFile(c:sold.gif); /storefilecontentintoXMLnode l_node1.nodeTypedValue=ado_stream.Read(-1);/-1=adReadAll ado_stream.Close(); xml_dom.documentElement.appendChild(l_node1); /wecancreatemoreXMLnodesformultiplefileupload /sendXMLdocumentotoWebserver varxmlhttp=newActiveXObject(Microsoft.XMLHTTP); xmlhttp.open(POST,,false); xmlhttp.send(xml_dom); /showservermessageinmessage-area div_message.innerHTML=xmlhttp.ResponseText; thanks John. 其他资源.The HttpRequest object provides client-side communication with a server.ExamplesreadyState How to return the state of the document. This property changes as the document is being loaded. responseText How to return the request as a string. status How to return the status of the operation, as a code. statusText How to return the status of the operation, as a string. The HttpRequest objectWith the httpRequest object you can send a request from the client to the server.If you are using JavaScript in IE 5.0, you can create the HttpRequest object with the following code:var xmlHTTP = new ActiveXObject(Microsoft.XMLHTTP)If you are using VBScript you create the httpRequest object with the following code:set xmlHTTP = CreateObject(Microsoft.XMLHTTP)The httpRequest object is not a part of the W3C DOM standard.Get XMLHow to get an xml file from the server using the httpRequest object (works only in IE):var xmlHttp = new ActiveXObject(Microsoft.XMLHTTP)xmlHttp.open(GET, note.xml, false)xmlHttp.send()xmlDoc=xmlHttp.responseTextTry it Yourself Netscape compatible code: xmlHttp = new XMLHttpRequest();xmlHttp.open(GET, note.xml, false);xmlHttp.send(null);xmlDoc = xmlHttp.responseText;Try it Yourself Send XMLYou can also send an xml document to an ASP page on the server, analyze the request, and send back the result.var xmlHttp = new ActiveXObject(Microsoft.XMLHTTP)xmlHttp.open(POST, demo_dom_http.asp, false)xmlHttp.send(xmlDoc)document.write(xmlHttp.responseText)The ASP page, written in VBScript:set xmldoc = Server.CreateObject(Microsoft.XMLDOM)xmldoc.async=falsexmldoc.load(request)for each x in xmldoc.documentElement.childNodes if x.NodeName = to then name=x.textnextresponse.write(name)You send the result back to the client using the response.write property.Try it Yourself Important NoteAt the moment, the Microsoft XMLHTTP object can only be run in the BROWSER.SERVER code that attempts to use the XMLHTTP to communicate with other Web servers, may function incorrectly or perform poorly.This is a bug in the HTTPRequest object. For more information read Microsofts Knowledge Base article Q237906. The rumor is that Microsoft will have this bug fixed in an upcoming release of the XML Library. In the meantime, you may have to use a commercially available ASPHTTP component.The httpRequest PropertiesProperty Description readyStateReturns the state of the documentresponseBodyReturns the response as an array of unsigned bytesresponseStreamReturns the response a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论