Home > Web Front-end > JS Tutorial > jQuery ajax传入参数含有特殊字符的解决方法

jQuery ajax传入参数含有特殊字符的解决方法

WBOY
Release: 2016-06-01 09:54:13
Original
1359 people have browsed it

在做ajax登录时候遇到的一个问题,

当传入参数含有特殊字符,比如:“$'#@”等。参数传递会有问题,无法正确获取。

<code class="language-javascript">$.ajax({
    url: '/user/login.ydd',
    type:'post',
    data:'name=abce&password=abcd&pwd',
    success: function(data){

    }
})</code>
Copy after login

我要传入的是用户名为:abc,密码为abcd&pwd的用户登录。但传入后台获取参数,会被password=abcd当作一个参数传递,&这个特殊将pwd分开了作为另一个参数解析了。

解决方法,这时候就需要ajax另外一种传递参数的方式

<code>$.ajax({
    url: '/user/login.ydd',
    type:'post',
    data:{'name':'abce','password':'abcd&pwd'},
    success: function(data){
    }
})</code>
Copy after login

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