2010-03-22 45 views
0
<script type="text/javascript"> 
    function testing() { 

     $.ajax({ 
      type: "POST", 
      url: "testing.php",  
      data: "call="+$("#abc").val(), 
      success: function(msg){ 
      alert(msg); 
      } 
     }); 
    } 
</script> 
<textarea id="abc" cols="" rows=""></textarea> 

我想發佈數據到testing.php,但是如果我得到像&這樣的特殊字符符號。它會造成問題。我如何去做呢?Jquery帶有&,+等符號

謝謝你

回答

2

使用encodeURIComponent

<script type="text/javascript"> 
function testing() { 

    $.ajax({ 
     type: "POST", 
     url: "testing.php",  
     data: "call=" + encodeURIComponent($("#abc").val()), 
     success: function(msg){ 
     alert(msg); 
     } 
    }); 
} 
</script> 
0

URL編碼這些字符。

& = &amp; 
0

在你testing.php文件,你可以使用函數addslashes包含文本數據之前。