First, Webservice.asmx
Process business data, generate weather data in the Getwhether method for Jqueryrequest.aspx call, code as follows:
Copy Code code as follows:
[System.Web.Script.Services.ScriptService]
public class WebService:System.Web.Services.WebService {
Public WebService () {
If you are using a design component, uncomment it to follow the line
InitializeComponent ();
}
[WebMethod]
public string Getwhether (string Cityid)
{
Random r = new Random ();
int degree = r.next (100);
String winfo = String. Format ("Today {0} ' s temperature is {1} degrees", Cityid, degree);
return winfo;
}
}
Second, ajaxrequest.aspx
Request the Webservice.asmx Getwhether (String Cityid) method by clicking on the button to get the weather data. The code is as follows:
Copy Code code as follows:
<title></title>
<script type= "Text/javascript" language= "JavaScript" src= "Js/jquery-1.3.2.js" ></script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "text" name= "Text1" id= "Text1"/><br/>
<input type= "text" name= "Text2" id= "Text2"/>
<br/>
<input type= "button" id= "Btn1" onclick= "Btncity_click" () "
Style= "WIDTH:55PX; height:20px; "/>
</div>
<div id= "DD" >
Sd
</div>
<div>
<script type= "Text/javascript" language= "JavaScript" >
function Btncity_click () {
var city = $ ("#Text1"). Val ();
$.ajax ({
URL: "Webservice.asmx/getwhether",
Data: {cityid:city},
Type: "Post",
Success:function (data, status) {
$ ("#dd"). HTML ("}
});
}
</script>
</div>
</form>
</body>