I am building a small ajax contact form and i am testing it with a basic php file(learning the whole jQuery ajax thing), but for some reason it doesn’t works.
Even if the data is correct it stil gives me the error code(if data = ok doent work).
here’s the basic jquery code
$(document).ready(function ($) {
$("#contactform").submit(function(){
var str = $(this).serialize();
$.ajax({
type: obj.attr('method'),
url: obj.attr('action'),
data: str,
dataType: 'html',
success: function(data){
$('.acf-wrap').ajaxComplete(function(event, request, settings){
if(data == 'OK'){
msg = 'success';
}else{
msg = data;
}
//display msg
$(this).html(msg);
});
}
});
return false;
});
});
test php file
if(1 == 1){
echo 'OK';
}else{
echo 'error!!!';
}
The data is probably a JSON string. JSON.parse the data and access the “d” property…
Actually wrote this answer on my phone… Might not be right. Couldn’t test it… 🙂