Jquery-ajax get () and Post () methods (26)

Source: Internet
Author: User
Tags http post
Get Two arguments, a URL, a callback post three parameters, a URL, a parameter, a callback
HTTP Request: Get vs. POST

Two common ways to request-respond on both the client and server side are: Get and POST. Get-Request data POST from the specified resource-submits the data to be processed to the specified resource

Get is basically used to obtain (retrieve) data from the server. Note: The Get method may return cached data.

POST can also be used to get data from the server. However, the POST method does not cache data and is often used to send data along with the request.

To learn more about get and POST and the difference between the two methods, read our HTTP method-get comparison POST. jQuery $.get () method

The $.get () method requests data from the server through an HTTP GET request. Syntax:

$.get (Url,callback);

The required URL parameters specify the URL you want to request.

The optional callback parameter is the name of the function that was executed after the request was successful.

The following example uses the $.get () method to retrieve data from a file on the server: instance

$ ("button"). Click (function () {
  $.get ("demo_test.asp", function (data,status) {
    alert ("Data: + Data +" \ Nstatus: "+ status);
  }";

Give it a shot yourself.

The first parameter of $.get () is the URL ("demo_test.asp") that we want to request.

The second parameter is the callback function. The first callback parameter holds the content of the requested page, and the second callback parameter holds the state of the request.

Hint: this ASP file ("demo_test.asp") looks like this:

<%
Response.Write ("This are some text from a external ASP file.")
%>
jQuery $.post () method

The $.post () method requests data from the server via an HTTP POST request. Syntax:

$.post (Url,data,callback);

The required URL parameters specify the URL you want to request.

The optional data parameter provides the information to be sent along with the request.

The optional callback parameter is the name of the function that was executed after the request was successful.

The following example uses $.post () to send data along with the request: instance

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

Give it a shot yourself.

The first parameter of $.post () is the URL ("demo_test_post.asp") that we want to request.

Then we send the data along with the request (name and city).

The ASP script in "demo_test_post.asp" reads these parameters, processes them, and then returns the results.

The third parameter is the callback function. The first callback parameter holds the content of the requested page, while the second parameter holds the state of the request.

Hint: this ASP file ("demo_test_post.asp") looks like this:

<% Dim fname,city Fname=request.form
("name") City=request.form ("City") Response.Write ("Dear" & fname & ".")
Response.Write ("Hope you live OK in" & City & ".") %> 
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.