2012-07-08 39 views
1

如果我在+注释符号中没有提交变量记录。有没有什么办法可以在jQuery中编码查询字符串?我尝试了一些方法,但他们没有工作+在ajax查询字符串中

$.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'); 
    } 
}); 

回答

1

您需要将数据编码为URL。

检查相关的帖子:Encode URL in JavaScript?

或者将您的数据作为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'); 
    } 
}); 
+0

我同意,数据应该作为一个对象传递。 – 2012-07-08 06:10:38