Ajax calls to Soap-xml Web services using jquery (call Soap-xml Web service with jquery Ajax) (translation + excerpt)

Source: Internet
Author: User

Suppose there is a based on. NET Web Service with the name Saveproduct

post/productservice.asmx http/1.1host:localhostcontent-type:text/xml; Charset=utf-8content-length: Lengthsoapaction: "Http://sh.inobido.com/SaveProduct"<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/">    <Soap:body>        <saveproductxmlns= "http://sh.inobido.com/">            <ProductID>Int</ProductID>            <ProductName>String</ProductName>            <manufacturedate>Datetime</manufacturedate>        </saveproduct>    </Soap:body></Soap:envelope>

The code for the AJAX call on the client with jquery is

varProductserviceurl = ' http://localhost:57299/ProductService.asmx?op=SaveProduct ';//preferably write this off from server side functionbeginsaveproduct (ProductID, ProductName, manufacturedate) {var SoapMessage=<soap:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <saveproduct xmlns=" http://sh.inobido.com/"> <productID>' + ProductID + '</productID> <productName>' + ProductName + '</productName> <manufactureDate>' + Manufacturedate + '</manufactureDate> </SaveProduct> </soap:Body> </soap:Envelope>‘; $.ajax ({url:productserviceurl, type:"POST", DataType:"XML", data: SoapMessage, complete: endsaveproduct, ContentType:"Text/xml; Charset=\ "Utf-8\" "}); return false;} function endsaveproduct (xmlhttprequest, status) {$ (xmlhttprequest.responsexml). Find (' Saveproductresult '). each (function() {varName = $ ( This). Find (' Name '). text (); });}

Description

    1. Type : types of requests sent-the type of request we ' re sending
    2. dataType: The type of response that is sent back-the type of the response will, in general, can be a type of HTML, JSON, and so on, but if it is a SOAP Web service, it must be defined as XML Type
    3. Data: Actual information sent to the Web service
    4. Complete: function (XMLHttpRequest, textstatus) {/* Code goes here */}
    5. contentType: The MIME content type of the request, similarly, if it is a SOAP Web service, it must be defined as "Text/xml"
    6. endsaveproduct: The XML data is now sent to the Web service, and once server server accepts the request and processes it, the Endsaveproduct method is called

If the XML response returned with jquery is processed, the SOAP reponse's schema definition must be understood, and the schema format of the saveproduct is as follows:

http/1.1 okcontent-type:text/xml; charset=utf-8content-length:length<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/">  <Soap:body>    <Saveproductresponsexmlns= "http://sh.inobido.com/">      <Saveproductresult>        <ID>Int</ID>        <Name>String</Name>        <manufacturedate>Datetime</manufacturedate>      </Saveproductresult>    </Saveproductresponse>  </Soap:body></Soap:envelope>

The returned response is placed in the XMLHttpRequest parameter responsexml , which can be used firebug or dev. Tool view, we can now use jquery to traverse the node of the XML and process the data.

Excerpt from: http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/

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.