开发者

Jquery with & , + and etc signs

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

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

I want to post the data to testing.php but if i got special characters like & sign. it will create the problem. How do i go about it?

Thank You


Use encodeURIComponent:

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

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


URL encode those characters.

& = &amp;


In your testing.php file you can use the function addslashes before the data that contains text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜