Have your PHP script return an XML document, and then parse that XML
with JQuery:
PHP:
/*
<FunctionResult>
<FunctionStatus success="1" message="Request processed" />
</FunctionResult>
*/
$document = DOMImplementation::createDocument();
$document->formatOutput = true;
$document->preserveWhitespace = true;
$functionResult = $document->createElement('FunctionResult');
$document->appendChild($functionResult);
$functionStatus = $document->createElement('FunctionStatus');
$functionResult->appendChild($functionStatus);
$success = true;
$message = 'Request successful';
...Do stuff that changes $success and $message if necesssary...
$functionStatus->setAttribute('success', $success);
$functionStatus->setAttribute('message', addslashes($message));
// Now respond to the requestor
Header("Content-type: text/xml", 1);
echo $document->saveXML();
Javascript:
$.post('http://myserver.com/ajax.php',
{ 'function' : 'getEfforts',
'parameter1' : something
},
function(xml) {
/*
<FunctionResult>
<FunctionStatus success="1" message="Request processed"
/>
</FunctionResult>
*/
var statusNode = $('FunctionStatus', xml).get(0);
var success = intToBool(statusNode.getAttribute('success'));
if(success === true) {
} else {
}
}
);