Very simple!
Please use JSON to return JSON string!
With JSON, we can return value easier than XML!
With XML, you must echo correct tag=))


2009/1/31 GreatBigBore <robfbis...@mac.com>:
>
> Have your PHP script return an XML document:
>
> 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';
>
> ...process the request and change $success and $message as
> necessary...
>
>        $functionStatus->setAttribute('success', $success);
>        $functionStatus->setAttribute('message', addslashes($message));
>
>        // Now respond to the requestor
>        Header("Content-type: text/xml", 1);
>        echo $document->saveXML();
>        error_log($document->saveXML());
>
> Javascript:
>
>        $.post('http://' + serverName + '/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 {
>                        }
>                }
>        );
>



-- 
ku...@urbanjar.info
/********************************************
* Người ta thưởng chỉ chú ý đến những kẻ lên như diều gặp gió! Nhưng
hỡi ôi, chỉ có cát, bụi và lông hồng mới là những thứ lên nhanh nhất
*/

Reply via email to