Reputation: 1330
I'm sending special characters to a PHP file via JQuery Ajax.
send_to_process.js
var special_charac = '!@#$%^&*()_+-=';
var dataString = 'data=' + special_charac;
$.ajax({
type: "POST",
url: "./process.php",
data: dataString,
cache: false,
success: function (result) {
}
});
process.php
<?php
$data= $_POST['data'];
echo $data;
?>
In the PHP file I'm getting all values except + and &
Why is it so ?
Does JQuery Ajax has got some limitations as to what data can you send to PHP script ?
Upvotes: 1
Views: 2744
Reputation: 4220
These are not AJAX limitations. These are URL limitations. eg & is used to split parameters. Just send data as json object
not:
data: dataString,
but
data: {data: special_charac}
or use encodeURI function to escape data
var dataString = 'data=' + encodeURI(special_charac);
Upvotes: 3