Web Basics (i) the most fundamental thing about the value of Ajax

Source: Internet
Author: User

http method of Get compare post

GET: Request data from the specified resource, POST: Submits the data to be processed to the specified resource

Get method:

Note that the query string (name/value pair) is sent in the URL of the GET request:

/test/demo_form.asp?name1=value1&name2=value2

Some additional comments about the GET request:

      • Get requests can be cached
      • GET requests remain in browser history
      • Get requests can be bookmark-Favorites
      • GET requests should not be used when handling sensitive data
      • Get request has a length limit
      • GET requests should only be used to retrieve data

Post method:

corresponding to the

1 will not be cached, 2 will not remain in the browsing record, 3 cannot bookmark, and 4 data length is unlimited.

Example:

  

$ ("button"). Click (function() {  $.post ("demo_test_post.asp",  {    name:" Donald Duck ", City    :" Duckburg "  },  function(data,status) {    Alert ("data:" + Data + "\nstatus:" + status);  } );

You can find that the post is a parameter and the request is sent together to the parameter Yes (URL) request is data name and city

This ASP code is as follows

<%Dim fname,cityfname=request.form ("name")City =request.form ("City") Response.Write ("Dear" & fname & "." ) Response.Write ("Hope you live ' Well ' & City &". " )%>

About using AJAX to send a value to the background: JSP page code

User name:<inputtype= "text"name= "User" id= "user"   />Email:<inputtype= "text"ID= "Email"name= "Email"  />    <DivID= "Showuser"></Div>   <inputtype= "button"value= "Get Value"ID= "Btnget"onclick= "GetValue ()" />

In JS, the code is as follows

function GetValue () {    $.ajax ({        type:"POST",        URL:"loaduser.action",        data:{            user:$ (' #user '). Val (),            email:$ (' #email '). Val ()        },        function  (response, status, XHR) {            console.log (response);            $ (' #showuser '). html (response[0].content);                    }    );};

Note Use user:$ (' #user '). Val (), get to the value where ' #user ', the function is id= "user" instead of name= "user" (try to know). If the background action can be directly in the background with the same name, using the Getset method to get the value.

Console.log (response) is the output of the returned value in the browser's console.

About radio button and select Collection how to get the corresponding value in Ajax JS

<inputID= "Usersex"name= "Usersex"type= "Radio"value= "Male"checked= "Checked" />&nbsp;&nbsp;male<inputID= "Usersex"name= "Usersex"type= "Radio"value= "female" />&nbsp;&nbsp;female<inputID= "Usersex"name= "Usersex"type= "Radio"value= "Confidential" />&nbsp;&nbsp;Confidentiality<S:selectList= "Listnums"ListValue= "Numname"ListKey= "NumId"name= "NumId"ID= "NumId"Headerkey= "Ol"Headervalue= "Please select"value= "Bean.numid"></S:select> 

The following JS is the method of value, have been used by their own, (about radio I think it is quite complicated, I do not know someone to provide more simple not)

var sex=document.getelementsbyname ("Usersex"); // can not Getelementbyid,byid and only reading the first value of the group var  for (var i = 0; i < sex.length; i++) {     if(sex[i].checked)      = sex[i].value;} // Sexvalue is the value you need. var numId = document.getElementById (' numId '). Value; // Select selection box More simple this sentence is OK.

  

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.