Invoking the WebService interface with JS

Source: Internet
Author: User

<script>$ (document). Ready (function () {                        varUsername = "Admin"; varPassword = "123456";

/ *==js Call WebService interface using Http-post mode (ie debug only) = =*/ //var host_url = "Http://localhost/Interface/Login.asmx/Login?" Username= "+ UserName +" &password= "+ Password; varurl = "Http://localhost/Interface/Login.asmx/Login"; varXmlHttp =NewActiveXObject ("Microsoft.XMLHTTP"); Xmlhttp.open ("POST", URL,false); Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); Xmlhttp.send ("Username=" + UserName + "&password=" + Password); if(Xmlhttp.readystate = = 4) { if(Xmlhttp.status = = 200) {document.getElementById ("Page"). InnerHTML =Xmlhttp.responsetext; } Else{alert ("Not 200! =" +xmlhttp.status); } } Else{alert ("Not 4! =" +xmlhttp.readystate); } /*==js Call WebService interface using SOAP (ie debug only) = =*/ //SOAP1.2 Request Data Format (please refer to Http://localhost/Interface/Login.asmx/Login?op=Login) vardata; Data= ' <?xml version= ' 1.0 ' encoding= ' utf-8 '?> '; Data= Data + ' <soap12:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/ 2001/xmlschema "xmlns:soap12=" Http://www.w3.org/2003/05/soap-envelope ">"; Data= Data + ' <soap12:Body> '; Data= Data + ' <login xmlns= ' http://mmp.test.com/DataInterface/' > '; Data= Data + ' <UserName> ' +username; Data= Data + ' </UserName> '; Data= Data + ' <Password> ' +password; Data= Data + ' </Password> ';Data= Data + ' </Login> '; Data= Data + ' </soap12:Body> '; Data= Data + ' </soap12:Envelope> '; varXMLHTTP =NewActiveXObject ("Microsoft.XMLHTTP"); Xmlhttp.open ("POST", "Http://localhost/Interface/Login.asmx",false); Xmlhttp.setrequestheader ("Content-type", "Application/soap+xml"); Xmlhttp.send (data); document.getElementById ("Page12"). InnerHTML =Xmlhttp.responsetext; }); </script>

Invoking the WebService interface with JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.