Detailed jquery in the $.ajax method to submit the form _jquery

Source: Internet
Author: User
Tags string format types of tables

Copy Code code as follows:

function PostData () {//Submit data functions
$.ajax ({//Call jquery Ajax method
Type: "POST",//Setting the format of the Ajax method submission data
URL: "ok.php",//Submit data to ok.php
Data: "Writer=" +$ ("#writer"). Val (),//The value in the input box writer as the submission
Success:function (msg) {//After a successful callback, the MSG variable is the content of the ok.php output.
Alert ("Data submitted successfully"); If necessary, you can display the value of the MSG variable in a DIV element
}
});
}

jquery Manual Description:
Data sent to the server. is automatically converted to the request string format. The GET request is appended to the URL. View the ProcessData option description to prevent this automatic conversion. Must be in the Key/value format. If you are an array, JQuery will automatically correspond to the same name for different values. such as {foo:["bar1", "Bar2"]} is converted to ' &foo=bar1&foo=bar2 '.
Example:

Copy Code code as follows:

$.ajax ({
Type: "POST",
URL: "some.php",
Data: "Name=john&location=boston",
Success:function (msg) {
Alert ("Data Saved:" + msg);
}
});

The parameters behind this data can be used in two types of tables: One is the normal URL argument, and one is written in the JSON array,
The above example data section can also be written like this: data: {name: "John", Location: "Boston"}. What is the difference between these two usages?

The nuances of usage are found today in development. The first one we use the URL to pass the parameter, if you add the symbol "&", the parameters may not receive or incomplete, such as "Data:" Name=john&location=boston ",",

If the value of name is "John&smith" This may be a problem, we can use JS inside the encodeURIComponent () method to escape,

But if you use data: {name: "John", Location: "Boston"} is written in this way, there is no need to escape, if escaped, will receive the escaped string

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.