I have this jQuery script:
$(document).ready(function(){
$('#submitNewExam').click(function(e){
e.preventDefault();
var examName = $('#newExam').val();
if ($.trim(newExam) != ''){
$.post('functions/addExam.php', { newExam: examName }, function(data){
console.log(data);
if(data =='error'){
$('#notify').html(data);
$('.alert').toggle();
}
});
}
$('.add').toggle();
});
});
and this PHP:
if(isset($_POST['newExam'])){
if(preg_match('/(<|>|"|%3c|%3e|%22)/', $_POST['newExam'])){
$a = 'error';
echo json_encode($a);
} else {
echo "something";
}
}
I'm able to output the response of PHP, what I'm not able to do is to make jQuery read that response and do something if the response in my example is equal to error. I have tried to encode the response in JSON and just to echo the response as a string, but none of those is working. In the console.log
I can see the response but jQuery is doing nothing.