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 ();
}
}