1

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 ?

1
  • Try escaping them. Commented Oct 10, 2016 at 9:33

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.