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);
});
});