The $.get () method and the $.post () method in jquery receive code

Source: Internet
Author: User
Tags json php tutorial

The $.get () method and the $.post () method in jquery receive code


When using jquery to implement AJAX applications, the methods often used are $.get () and $.post (), and two methods are used to receive the parameters passed by them in different ways, when using $.post (), the way to receive is: request.form["myID "];
In the use of $.get (), the Received trial is: request.querystring["myID"];
=======================================================================
The use of the following methods:
Use the source code of the page
<title></title>
<script type= "text/page special effects" src= "Http://wenfuchun.blog.163.com/blog/jquery-1.3.2.js "><script type= "Text/javascript" >
function Myclick () {
$.post ("innerajax.asp tutorial X", {"myID": $ ("#Text1"). Val ()}, function (Date) {
$ ("#span1"). HTML (Date);/note here
});
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input id= "Text1" type= "text"/><br/>
<span id= "Span1" > here will appear my content </span><br/>
<input id= "Button1" type= "button" value= "button" onclick= "Myclick" () "/></div>"
</form>
</body>
--------------------------------------------------------------------------------------------------------------- ------
CS code in innerajax.aspx page

protected void Page_Load (object sender, EventArgs e)
{
String my =request.form["myID"];//note here
Response.Write ("This is my new message" +my);
}

===========================================================================
When you pass a parameter to a GET method:

Use AJAX get requests to change the text of a DIV element:

$ ("button"). Click (function () {
$.get ("Demo_ajax_load.txt", function (Result) {
$ ("div"). html (result);
});
});
Give it a shot yourself.
Definitions and usage
The Get () method loads information through a remote HTTP GET request.

This is a simple GET request function to replace the complex $.ajax. Callback functions can be invoked when the request succeeds. If you need to perform a function when an error occurs, use $.ajax.

Grammar
$ (selector). Get (Url,data,success (RESPONSE,STATUS,XHR), dataType) parameter description
URL required. Specify which URL to send the request to.
Data is optional. Specify the data to be sent to the server along with the request.
Success (RESPONSE,STATUS,XHR) is optional. A function that is required to run when a request succeeds.

Additional parameters:

Response-Contains the result data from the request
Status-Contains the state of the request
XHR-Contains XMLHttpRequest objects

DataType Optional. Specify the data type of the expected server response.

By default, JQuery will intelligently judge.

Possible types:

"XML"
"HTML"
"Text"
"Script"
"JSON"
"Jsonp"

Detailed description
This function is shorthand for Ajax functions, equivalent to:

$.ajax ({
Url:url,
Data:data,
Success:success,
Datatype:datatype
Depending on the MIME type of the response, the return data passed to the success callback function is also different, which can be an XML root element, a text string, a JavaScript file, or a JSON object. You can also pass the response's text state to the success callback function.

For JQuery 1.4, you can also pass the XMLHttpRequest object to the success callback function.

Example
Request test.php Tutorial Web page, ignore return value:

$.get ("test.php"); more examples
Example 1
Request test.php Web page, transfer 2 parameters, ignore return value:

$.get ("test.php", {name: "John", Time: "2pm"}); Example 2
Displays the test.php return value (HTML or XML, depending on the return value):

$.get ("test.php", function (data) {
Alert ("Data Loaded:" + data);
); Example 3

Displays the test.cgi return value (HTML or XML, depending on the return value), and adds a set of request parameters:

$.get ("test.cgi", {name: "John", Time: "2pm"},
function (data) {
Alert ("Data Loaded:" + data);
});

--------------------------------------------------------------------------------------------------------------- ------------
CS code in innerajax.aspx page

protected void Page_Load (object sender, EventArgs e)
{
String my =request.querystring["myID"]; Watch this.
Response.Write ("This is my new message" +my);
}

------------------------------------please refer to the following parameters----------------------------------------

$.get ("Myedit.ashx?time=" +math.random (), {action: "Getuserschool", Uid:uid},function (Data,status) {}); $.get () method, passing parameters to the general handler

$.post ("Myedit.ashx?time=" +math.random (), {"Action": "Getuserschool", "UID": uid},function (Data,status) {}); $.post () method, passing parameters to the general handler


$_post

Request test.php Web page, ignore return value:

$.post ("test.php"); Tiy instance
Change the text of a DIV element through an AJAX POST request:

$ ("input"). KeyUp (function () {
txt=$ ("Input"). Val ();
$.post ("demo_ajax_gethint.asp", {suggest:txt},function (result) {
$ ("span"). HTML (result);
});
});

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.