Home > Web Front-end > JS Tutorial > body text

Summary of usage of data parameter of ajax method in Jquery_jquery

WBOY
Release: 2016-05-16 17:00:43
Original
1084 people have browsed it
Copy code The code is as follows:

$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston", //The first way to pass parameters
// data: {name:"John",location:"Boston" } //The second way to pass parameters
// data: {foo:["bar1", "bar2"]} is converted to '&foo=bar1&foo=bar2'
/*
The first way we Use url to pass parameters. If the "&" symbol is added to the parameter, the parameter may not be received or may be incomplete.
For example, "data: "name=John&location=Boston"," if the value of name is "john&smith" There may be problems when writing this way.
We can use the encodeURIComponent() method in JS to escape.
But if we write it in this way: {name: "John", location: "Boston"} If
is escaped, the received string will be the escaped string
*/
success: function(msg){
alert( "Data Saved: " msg );
}
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!