Jquery +;在ajax查询字符串中

Jquery +;在ajax查询字符串中,jquery,ajax,urlencode,Jquery,Ajax,Urlencode,如果注释中有+符号,则不提交变量记录。有没有办法在jquery中对查询字符串进行编码?我试过一些方法,但都不管用 $.ajax({ type: 'post', url: rootURL + 'services/service.php?method=insertcomment', data: 'comment=' + comment+'&storyid='+storyid, dataType: 'json', success: functi

如果注释中有+符号,则不提交变量记录。有没有办法在jquery中对查询字符串进行编码?我试过一些方法,但都不管用

$.ajax({
     type: 'post',
     url: rootURL + 'services/service.php?method=insertcomment',
     data: 'comment=' + comment+'&storyid='+storyid,
     dataType: 'json',
     success: function (data) {
           if(data.code == 200)
                 $('#success-message')..show();
           else
                alert('failure');
     }
});

您需要将数据编码为URL

查看相关帖子:

或将数据作为JSON对象传递:

$.ajax({
     type: 'post',
     url: rootURL + 'services/service.php?method=insertcomment',
     data: {comment : comment, storyid : storyid},
     dataType: 'json',
     success: function (data) {
           if(data.code == 200)
                 $('#success-message').show();
           else
                alert('failure');
     }
});

您需要将数据编码为URL

查看相关帖子:

或将数据作为JSON对象传递:

$.ajax({
     type: 'post',
     url: rootURL + 'services/service.php?method=insertcomment',
     data: {comment : comment, storyid : storyid},
     dataType: 'json',
     success: function (data) {
           if(data.code == 200)
                 $('#success-message').show();
           else
                alert('failure');
     }
});

我同意,数据应该作为对象传递。我同意,数据应该作为对象传递。