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

Jquery中ajax方法data参数的用法小结_jquery

WBOY
Release: 2016-05-16 17:00:43
Original
1071 people have browsed it
复制代码 代码如下:

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston", //第一种方式传参
  // data: {name:"John",location:"Boston"}  //第二种方式传参
  // data: {foo:["bar1", "bar2"]} 转换为 '&foo=bar1&foo=bar2'
  /*
 第一种我们用url传参,参数里面如果加带"&"这个符号的话,可能参数接收不到或不完整,
 如“ data: "name=John&location=Boston",” 如果name的值是"john&smith"这样写可能就会有问题,
 我们可以用JS里面的encodeURIComponent()方法进行转义,
 但如果用data: {name:"John",location:"Boston"}这种方式写的话就不需要进行转义,
 如果转义的话,接收的将是转义后的字符串
  */
   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!