The first way to submit a post is in the traditional way, judging the browser to make a POST request.
varXmlobj;//Defining XMLHttpRequest Objects functioncreatexmlhttprequest () {if(window. ActiveXObject)//create ActiveXObject Object if active Xobject is supported by the current browser { //xmlobj = new ActiveXObject ("Microsoft.XMLHTTP"); Try{xmlobj=NewActiveXObject ("Msxml2.xmlhttp"); } Catch(e) {Try{xmlobj=NewActiveXObject ("Microsoft.XMLHTTP"); } Catch(E) {xmlobj=false; } } } Else if(window. XMLHttpRequest)//if the current browser supports XMLHTTP Request, the XMLHttpRequest object is created{xmlobj=NewXMLHttpRequest (); } } functionSubmitarticle (Act,cityname,antique)//Main program Functions{createxmlhttprequest (); //Creating Objects //var parm = "Act=firstweather";//construct URL parameter //antique = Escape (antique); varParm = "act=" + act + "&cityname=" + CityName + "&antique=" + antique;//Constructing URL Parameters //Xmlobj.open ("POST", "{dede:global.cfg_templeturl/}/."). /include/weather.php ", true); Call weather.phpXmlobj.open ("POST", "/weather/include/weather.php",true);//Call weather.phpXmlobj.setrequestheader ("Cache-control", "No-cache"); Xmlobj.setrequestheader ("ContentType", "text/html;charset=uft-8")//Specify the encoding to sendXmlobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded;");//Set Request header informationXmlobj.onreadystatechange= Stathandler;//determines the status value of a URL call and processesxmlobj.send (parm);//set to send to server data }
The second way is to submit a POST request in the form of a virtual form
functionPost (URL, PARAMS) {vartemp = document.createelement ("form"); Temp.action=URL; Temp.method= "POST"; Temp.style.display= "None"; for(varXinchPARAMS) { varopt = document.createelement ("textarea"); Opt.name=x; Opt.value=Params[x]; //alert (opt.name)Temp.appendchild (opt); } document.body.appendChild (temp); Temp.submit (); returntemp; Call method such as post (' Pages/statisticsjsp/excel.action ', {html:p rnhtml,cm1: ' SDSDDSD ', cm2: ' haha '});
Reprinted from: http://wiseideal.iteye.com/blog/1582947
JS two kinds of post mode