Jquery+ajax Call WebService Instance

Source: Internet
Author: User

Jquery+ajax Call WebService Instance
This article is using the ASP tutorial. NET WebService and jquery Ajax to do an AJAX example

<script language= "Web Effects" >
$ ("document"). Ready (function () {
$ ("#mmlog"). Append ("Data"); This sentence is valid and there is data at the specified location on the page
$ ("#btn"). Click (function () {
Alert ("SDFSDF");/effective
$.ajax ({
Async:false,
Type: "Post",
ContentType: "Application/json",
URL: "Webservice.asmx/helloworld",
Data: "{}",
DataType: "XML",
Cache:false,
Success:function (data, Textstatus, XMLHttpRequest) {
Alert ("OK"); Type: "Get", at least 1 times inside 10 times invalid; Type: "POST", invalid
$ ("#mmlog"). Append ("Data"); Showed up and disappeared again.
alert (data);
},
Error:function (xml,status) {alert (status);}//type: "Post", status= "error"
});
});

})
</script>

Webservic.asmx file

Public class Dataservice:system.web.services.webservice {

  public DataService () {

 //If you are using a design component, uncomment the following line  
 //initializecomponent (); 
 }
  [WEBMETHOD]
  public string HelloWorld () {
  return ' Hello World ';
 }

  [WebMethod]
  public int AppendData (string Sdev, String x, string y)
  {
  string s = String.Format ("INSERT INTO Zry_ Current (Zdev,zx,zy) values (' {0} ', {1},{2}) ", Sdev, X, y);
  return accesshelper.executenonquery (s);
 }

  [WebMethod]
  public string ReadData (string Sdev, String Dayid)
  {
  string s = Stri Ng.format ("Select Zx,zy from zry_current where zdev= ' {0} ' and Zday={1}", Sdev, Dayid);
  DataSet ds = Accesshelper.executedataset (s);
  Ds.datasetname = "zry_current";
  return Ds.getxml ();
 }
}

Related Article

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.