1

如果我在评论变量记录中有 + 符号,则未提交。有什么办法可以在 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');
     }
});
4

1 回答 1

1

您需要将数据编码为 URL。

查看相关帖子:在 JavaScript 中编码 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');
     }
});
于 2012-07-08T06:08:19.157 回答