url:"GetCommentById.ashx?ctype=insert&cid="+documentId+"&details="+Quote_data+c_details+"&ReplyCommentId="+ReplyCommentId用Jquery 时,如果传递的内容中 含有 &,势必会引发异常 或者出现错误。该怎么解决这一问题呢?首先考虑的 是用 ASCII 替换,替换掉再提交,入库之前还原。Jquery 本身 有没有解决这一问题的 方法呢?

解决方案 »

  1.   

    用escape编码, 服务器端会自动解码的
    url:"GetCommentById.ashx?ctype=insert&cid=" + escape(documentId) + "&details=" + escape(Quote_data) + escape(c_details) + "&ReplyCommentId=" + escape(ReplyCommentId) 
      

  2.   

        var params = { name:edwin,company:E };
        var str = jQuery.param(params);
        alert(str );//output message will be "name=edwin&company=E"   so you can use json string as param.   
      

  3.   

    jQuery的Get请求说明:
    jQuery.get( url, [data], [callback], [type] ) 
    其中data:Key/value pairs that will be sent to the server.
    所以你的请求可以写成:
    url:"GetCommentById.ashx",
    data:{
    'ctype':'insert',
    'cid':documentId,
    ...
    ...
    }
      

  4.   

    是的, 顶2 3 4 楼
    参数最好用json传入, 这样可以节省很多解析验证的步骤后台传回json也会方便很多.