I'm using AJAX
to save data in a jquery mobile
project. I´m using the below code and the data gets saved, but for some reason I do get parseerror
in concole and Error #2
alert is thrown. However the other one , alert(data['error']);
just print out some actual jquery code?
$("#submit").click(function(){
var formData = $("#event_form").serialize();
$.ajax({
type: "POST",
url: "include/handler/create.ajax.php",
cache: false,
data: formData,
success:function(data){
if(data['error']){
alert('Error #1');
alert(data['error']);
}else{
alert('Success');
alert(data['success']);
$('#event_form').trigger("reset");
}
},
error: function(data, errorThrown){
alert('Error #2');
alert(data['error']);
console.log(errorThrown);
}
});
return false;
});
In the AJAX handler I return message by:
$msg = array("error"=>"Technical error");
echo json_encode($msg);
die;