Jquery Ajax Learning Instance 3 sends a request to WebService, calling method return data _jquery

Source: Internet
Author: User
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>

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.