Home >Web Front-end >JS Tutorial >jquery+ajax获取特殊字符

jquery+ajax获取特殊字符

WBOY
WBOYOriginal
2016-06-01 09:54:11846browse

在用jquery加ajax写的时候,发现如果传进去的数据包含&则无法获取数据而+号的话就会被判定为空,解决办法就是使用encodeURIComponent()函数对要发送的数据进行编码.

<code class="language-javascript">function ajax() {
    $val = encodeURIComponent($('#note').val());
    $.ajax({
        type: 'post',
        url: 'xxx.php',
        data: 'txt=' + $val,
        success: function(data) {
            $("#remove").empty();
            $("#main").html(data);
            $(".chg_area").hide();
        }
    });
};</code>

这样就能传&+这些特殊符号了

Statement:
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