The problem encountered today is the same as the following: the parameter format problem. The following article solves my problem.
Http://www.dotblogs.com.tw/topcat/archive/2010/09/10/17655.aspx
This is not often used, but it is really easy to forget, so I will write an article to record it, so that I can take an example test later.
First, we need a specific web service, which is specially placed in different resources.
Xxx/ws001.asmx
The content is as follows:
Imports system. webimports system. web. servicesimports system. web. services. protocols 'to allow the use of ASP.. Net Ajax calls this web server from the command terminal. Cancel the next line. '<System. web. script. services. scriptservice ()> _ <WebService (namespace: = "http://tempuri.org/")> _ <webservicebinding (conformsto: = wsiprofiles. basicprofile1_1)> _ <global. microsoft. visualBasic. compilerservices. designergenerated ()> _ public class ws001 inherits system. web. services. webService <webmethod ()> _ Public Function helloworld () as string return "Hello World" end function <webmethod ()> _ Public Function mytest1 (byval usrid as string, byval discussid as decimal) as string return "hi" + usrid + ", <br/> discussid:" + discussid. tostring + "<br/>" + now. tostring () end functionend class
Then, in the response plane, assign a listener named btn1.
<input id="btn1" type="button" value="XXX" />
Then, the author uses jquery ajax to access the Web Service
<script type="text/javascript"> $(document).ready(function () { $('#btn1').click(function () { alert('xx'); var strURL = 'XXX/ws001.asmx/myTest1'; //var strURL = 'XXX/ws001.asmx/HelloWorld'; $.ajax({ type: 'POST', url: strURL, dataType: 'xml', data: { UsrID: "topcat", DiscussID: "3" }, success: function (oXml) { alert($('string', oXml).text()); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }); }) </script>
Note that there are many data transmission methods available on the Internet. Currently, this method is okay.
Data: {usrid: "topcat", discussid: "3 "},