I have a textarea where a user can enter code with the id of ‘code_box’.
<textarea id = 'code_box'></textarea>
I then have this jQuery which uses ajax to send the code to my PHP script which processes it.
$('#submit_button').click(function() {
var code= $('#code_box').val();
if(code.length > 0) {
$.ajax ({
type: 'POST',
url: '/php/handle_code.php',
cache: false,
data: 'code=' + encodeURIComponent(code),
success: function(output) {
window.location = output;
}
});
}
});
However, when trying to send code through, it doesn’t actually send it. I have verified that is has the code in the “paste” variable. I have also verified that the $_POST[‘code’] variable doesn’t actually receive anything on the PHP side, so the problem must be in the ajax request. Other inputs work, for example plain text, which goes through fine. Is there anything else I need to do to sanitize the code before I send it to the PHP script with ajax?
EDIT:
Here is some code that goes through fine:
This is plain text.
Here is some that doesn’t:
<?php
echo "test";
?>
I think you are not sending the data in proper way which ajax needs:
Try this one, not tested but might help you.
information: http://api.jquery.com/jQuery.ajax/