This article
Introduce the Get () function first:
Url,[data],[callback],[type]
Parameter description:
URL: The URL address of the page to be loaded
Data: Key/value parameter to be sent.
Callback: callback function when load succeeds.
Type: Returns the content format, XML, HTML, script, JSON, text, _default
Description
Get Way:
You can transfer simple data in Get mode, but the size is typically limited to 1KB, the data is appended to the URL (HTTP header transfer), that is, the browser appends individual form field elements and their data to the resource path in the request line in the format of the URL parameter. The most important point is that it is cached by the client's browser, so that other people can read the customer's data, such as account number and password, from the browser's history. Therefore, in some cases, the Get method poses a serious security problem.
First, establish a testget.php instance:
The code is as follows |
Copy Code |
<?php $web = $_get[' webname ']; echo "The website you are visiting now is:". $web; ?> |
However, the establishment of the ajax.html file:
The code is as follows |
Copy Code |
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> <script type= "Text/javascript" src= "/jquery-1.7.1.min.js" ></script> <script> $ (document). Ready (function () { $ ("#btn"). Click (function () { $.get ("testget.php", {web: "www.111cn.net"},function (data,textstatus) { $ ("#result"). Append ("Data:" +data); $ ("#result"). Append ("<br>textstatus:" +textstatus); }); }); }); </script> <body> <input type= "button" value= "Test" id= "btn"/> The contents of <div id= "Result" ></div> </body>
|
You need to be aware of using get methods:
1 for Get requests (or any that involve passing parameters to the URL), the passed parameters are processed first by the encodeURIComponent method. Example: var url =
The code is as follows |
Copy Code |
"Update.php?username=" +encodeuricomponent (username) + "&content=" +encodeuricomponent (content) + "&id=1"; |