Hi, I have a form that submits to a PHP script with Jquery and Ajax. The PHP script returns some XML. For some reason the Ajax success function is not firing, and the error ones is.
Can anybody see where I'm going wrong?
My Jquery is as follows
$('#submit-excuse').submit(function (event) {
event.preventDefault();
ws_url = 'http://jacamo.epiphanydev2.co.uk/content/inc/excuse-submit.php?excuse='+$('input#excuse').val();
$.ajax({
type: 'GET',
url: ws_url,
dataType: "xml",
beforeSend: function() {
$('p#response').text('Sending.');
},
success: function(xmlIn) {
results = xmlIn.getElementsByTagName("ReportID");
},
error: function() {
$('p#response').text('Error.');
}
});
});
And my PHP script is as follows:
$excuse = $_GET['excuse'];
$badwords = array (
'one',
'two',
'three',
'four',
'five'
);
if ($excuse == '') {
$error = 'enter something';
} else {
foreach ($badwords as $word) {
$pos = strpos($excuse, $word);
if($pos !== false) {
$passed = false;
}
}
if ($passed !== false) {
$username = 'xxxxx';
$password = 'xxxxx';
$message = $excuse;
$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$passed = 'yes';
}
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "\t<result>\n";
echo "\t\t<passed>" . $passed . "</passed>\n";
echo "\t</result>";
}
Thanks