41
I am still struggling to get my head around the ins and out of JQUERY, AJAX and PHP.
I can now call the PHP OK, process the form elements and send an email, but I am not handling the return to the AJAX. I am always getting the error: selector activated and when I try to list the supposed JSON returned, I get info, that is obviously wrong.
PHP with supposed JSON return
<?php
touch('phpTouch.txt');
// process email
$email=1;
if ($email) {
$value = array('return' => 1, 'msg1' => 'Message sent OK, we will be in touch ASAP');
} else {
$value = array('return' => 0, 'msg1' => 'Message Failed, please try later');
}
$output = $json->encode($value);
echo $output;
?>
Javascript and AJAX
function submitForm(evt) {
$('#msgid').html('<h1>Submitting Form (External Routine)</h1>');
if ($('#formEnquiry').valid() ) {
$("#msgid").append("<h1>(Outside Ready) VALIDATED send to PHP</h1>");
$.ajax({
url: "ContactFormProcess3.php",
type: "POST",
data: $('#formEnquiry').serialize(),
dataType: "json",
success: function (data) {
alert("SUCCESS:");
for(var key in data) {
$('#msgid').append(key);
$('#msgid').append('=' + data[key] + '<br />');
}
},
error: function (data) {
alert("ERROR: ");
for(var key in data) {
$('#msgid').append(key);
$('#msgid').append('=' + data[key] + '<br />');
}
}
});
} else {
$('#msgid').append('<h1>(Outside Ready) NOT VALIDATED</h1>');
}
evt.preventDefault();
};
Listing of supposed JSON data
readyState=4
setRequestHeader=function (a,b){if(!s){var c=a.to