JS and jquery call C # WebService

Source: Internet
Author: User

1.CodeComment removed

// To allow ASP. Net ajax to call this web service from a script, cancel the comments to the downstream.
// [System. Web. Script. Services. scriptservice]

2. The JS call method is as follows:

VaR request = '<? XML version = "1.0" encoding = "UTF-8"?> '; Request + =' <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"> 'request + = '<soap12: body> 'request + = '<updatefacultativere xmlns = "http://tempuri.org/"> 'request + =' <facnum> 12313 </facnum> 'request + = '<facverstion> 2 </ facverstion> 'request + = '<date> string </date> 'request + =' <description> string </description> 'request + = '</updatefacultativere> 'request + = '</soap12: body> 'request + = '</soap12: envelope> 'var Req = new XMLHttpRequest (); req. open ("Post", 'HTTP: // localhost: 34869/crmservice. asmx ', true) // responses will return XML. it isn' t possible to return JSON. // req. setRequestHeader ("accept", "application/XML, text/XML, */*"); req. setRequestHeader ("Content-Type", "application/soap + XML; charset = UTF-8"); req. setRequestHeader ("Content-Length:", request. length); req. setRequestHeader ("soapaction", "http://tempuri.org/UpdateFacultativere"); req. onreadystatechange = function () {DOR (req, successcallback, errorcallback) ;}; req. send (request );

3. jquery calls the following method:

 $. ajax ({URL:  'HTTP: // localhost: 34869/crmservice. asmx/updatefacultativere ', data: {facnum:  '000000', facverstion: 10, Date: '000000 ', description: '000000' }, datatype:  "XML" , type: " Post ", success:   function   (XML) {  debugger   alert (XML) ;}, error:   function   (XML, status) {  debugger  }});  

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.