Getting started with an instance (Ajax)

Source: Internet
Author: User

Static Page

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Title> No title page </title>
  5. <SCRIPT type = "text/JavaScript" src = "jquery/jquery. js">
  6. // <SCRIPT type = "" src = "/>
  7. </SCRIPT>
  8. <SCRIPT type = "text/JavaScript">
  9. /*
  10. Encodeuri Method
  11. Encode the parameters passed by the URL
  12. Encodes a text string into a valid Uniform Resource Identifier (URI ).
  13. */
  14. Function createquerystring (){
  15. VaR firstname = encodeuri ($ ("# firstname"). Val ());
  16. VaR Birthday = encodeuri ($ ("# birthday"). Val ());
  17. // Combine them into objects
  18. VaR querystring = {firstname: firstname, birthday: Birthday };
  19. Return querystring;
  20. }
  21. Function dorequestusingget (){
  22. $. Get ("ajaxserve. aspx", createquerystring (),
  23. // Send a GET request
  24. Function (data ){
  25. $ ("# Serverresponse" pai.html (decodeuri (data ));
  26. }
  27. );
  28. }
  29. Function dorequestusingpost (){
  30. $. Post ("ajaxserve. aspx", createquerystring (),
  31. // Send a POST request
  32. Function (data ){
  33. $ ("# Serverresponse" pai.html (decodeuri (data ));
  34. }
  35. );
  36. }
  37. </SCRIPT>
  38. </Head>
  39. <Body>
  40. <H2> enter name and birthday </H2>
  41. <Form>
  42. <Input type = "text" id = "firstname"/> <br/>
  43. <Input type = "text" id = "Birthday"/>
  44. <Input type = "button" value = "get" onclick = "dorequestusingget ();"/> <br/>
  45. <Input type = "button" value = "Post" onclick = "dorequestusingpost ();"/>
  46. </Form>
  47. <Div id = "serverresponse"> </div>
  48. </Body>
  49. </Html>

Dynamic page

  1. Protected void page_load (Object sender, eventargs E)
  2. {
  3. // Response. Write ("background data ");
  4. If (request. httpmethod = "Post ")
  5. Response. Write ("post:" + request ["firstname"] + ", your birthday is" + request ["Birthday"]);
  6. Else if (request. httpmethod = "get ")
  7. Response. Write ("Get:" + request ["firstname"] + ", your birthday is" + request ["Birthday"]);
  8. }
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.