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.
& = &
In your testing.php
file you can use the function addslashes before the data that contains text.
精彩评论