jQuery ajax传递特殊字符参数(例如+)

使用jQuery ajax向后台传递参数para=1+1时后台接收到的参数为para=1 1,解决方案是 使用json传递,代码如下。

var url = "/test/check";
    $.ajax({
        type: "post",
        url: url,
//      data: "para=1+1",  data为字符串时 后台接收到的参数为 1 1
        data: {"para":1+1}, // data为json数据时 后台接收到的参数为 1+1
        cache: false,
        async : false,
        dataType: "json",
        success: function (data ,textStatus, jqXHR)
        {
            if("true"==data.flag){
               alert("合法!");
                return true;
            }else{
                alert("不合法!错误信息如下:"+data.errorMsg);
                return false;
            }
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) {      
            alert("请求失败!");
        }
     });
posted @ 2015-08-13 17:23  Java碎碎念  阅读(1847)  评论(0编辑  收藏  举报