Jquery ajax parameter transfer and data storage instance

Source: Internet
Author: User

Jquery ajax parameter passing and data storage instances are suitable for beginners. First, let's talk about how to use ajax + php for data operations, then we will detail the help instructions on jquery ajax.

Jquery ajax parameter transmission and data storageThe instance is suitable for beginners. First, let's talk about how to use the ajax + php tutorial to perform data operations, and then give a detailed introduction to the help instructions of jquery ajax.

Var info = document. getelementbyid ("txt"). value;
Jquery. ajax ({
Type: 'get ',
Url: 'http: // localhost: 8080/jdom/hehe. do? Act = webpage special effects on ',
Data: "& info =" + info,
Cache: false,
Datatype: 'json', // specifies the return type
Error: function (data, status, e ){
Alert ("hehe ");

Look at a jquery ajax php instance.

<Title> ajax </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Script type = "text/Webpage effects" src = "http: // localhost/leb/auto/js/jquery-latest.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# Config"). submit (function (){
$. Ajax ({
Type: "post ",
Url: "addpage. php ",
Data: $ ('# config '). serialize (), // format the form parameter, or use data: {'folder': $ ('input [name = folder] '). val (), 'page': $ ('input [name = page] '). val ()},
Datetype: 'text ',
Success: function (data) {// data returned when the data is successfully submitted
Alert (data );
Return false;
<Form name = "config" method = "post" id = "config">
<Div class = "infotitle"> main directory: </div>
<Input name = "folder" type = "text"/>
<Div class = "infotitle"> Page name: </div>
<Input name = "page" type = "text"/>
<Div class = "submit">
<Button type = "submit" id = "submit"> OK </button>

// Addpage. php file

$ Folder = $ _ post ['folder'];
$ Page = $ _ post ['page'];
Using file1_fopen('result.htm', 'w ');
Fwrite (
$ File,
"Folder:". $ folder. '<br> '.
"Template page:". $ page. '<br>'
Fclose ($ file );


Parameter Name Type Description
Url String (Default: Current page address) the address of the request sent.
Type String (Default: "get") Request Method ("post" or "get"). The default value is "get ". Note: Other http request methods, such as put and delete, can also be used, but are only supported by some browsers.
Timeout Number Set the request timeout (in milliseconds ). This setting overwrites the global setting.
Async Boolean (Default: true) by default, all requests are asynchronous requests. To send a synchronization request, set this option to false. Note: The synchronous request locks the browser. Other operations can be performed only after the request is completed.
Beforesend Function Before sending a request, you can modify the function of the xmlhttprequest object, for example, adding a custom http header. The xmlhttprequest object is a unique parameter.
function (xmlhttprequest) {
this; // the options for this ajax request
Cache Boolean (Default: true) New jquery 1.2 function. setting this parameter to false will not load request information from the browser cache.
Complete Function Callback Function after the request is complete (called when the request is successful or fails ). Parameter: xmlhttprequest object, success information string.
function (xmlhttprequest, textstatus) {
this; // the options for this ajax request
Contenttype String (Default: "application/x-www-form-urlencoded") Content Encoding type when sending information to the server. The default value is applicable to most applications.
Data Object,
The data sent to the server. Will be automatically converted to the request string format. The get request will be appended to the url. View the description of the processdata option to disable automatic conversion. It must be in key/value format. If it is an array, jquery automatically corresponds to the same name for different values. For example, {foo: ["bar1", "bar2"]} is converted to '& foo = bar1 & foo = bar2 '.
Datatype String

Expected data type returned by the server. If this parameter is not specified, jquery will automatically return responsexml or responsetext Based on the mime information of the http package and pass it as a callback function parameter. Available values:

"Xml": returns an xml document, which can be processed by jquery.

"Html": returns plain text html information, including script elements.

"Script": returns plain text javascript code. Results are not automatically cached.

"Json": Return json data.

"Jsonp": jsonp format. When calling a function in the form of jsonp, such as "myurl? Callback =? "Will jquery be replaced automatically? For the correct function name to execute the callback function.

Error Function (Default: automatically determines (xml or html) This method is called when a request fails. This method has three parameters: xmlhttprequest object, error message, and (possibly) captured error object.
Function (xmlhttprequest, textstatus, errorthrown ){
// Generally, textstatus and errorthown have only one value.
This; // the options for this ajax request
Global Boolean (Default: true) Whether to trigger a global ajax event. Setting false does not trigger global ajax events, such as ajaxstart or ajaxstop. Can be used to control different ajax events
Ifmodified Boolean (Default: false) obtain new data only when the server data changes. Use the last-modified header information of the http packet to determine.
Processdata Boolean (Default: true) by default, data sent is converted to an object (technically not a string) with the default content type "application/x-www-form-urlencoded ". If you want to send the dom tree information or other information that does not want to be converted, set it to false.
Success Function Callback Function after successful request. This method has two parameters: the server returns data and returns the status.
function (data, textstatus) {
// data could be xmldoc, jsonobj, html, text, etc...
this; // the options for this ajax request

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.