Topic: value from xajax response object

I'm trying to extract value from response xajax object. With no success. Here is the php function:

function testFormFail( $formData, $a, $b )
    $objResponse=new xajaxResponse();
    $objResponse->alert("POST\nformData: ".print_r($formData, true)." a:".$a." b:".$b);
    return $objResponse;

And here is function in which I'm trying to get value "Yippie":

        <input type = "submit"
               value = "Form Call with Inline Callback (also onFailure test)"
                onclick = "xajax.request({xjxfun:'testFormFail'}, {
                [xajax.getFormValues('testForm1'), '2', '3'],
                onRequest: function() { alert('In inline onRequest'); },
                onComplete: function(args) {
                    alert('In inline onComplete ' + args;
                onFailure: function(args) { alert('In inline onFailure -- status is: ' + args.request.status); }
    return false;" />

Alert message shows "object Object" and I can't find a way to get something from this object (array?).
args.xjxrv, args[0], args.request.xjxrv -- nothing works. What else can I try? Returned json array is ok -- I can see it in Firebug:

{"xjxrv":"Yippie","xjxobj":[{"cmd":"al","data":"POST\nformData: Array\n(\n    [textBox1] => Here is some text.\n)\n a:2 b:3"},{"cmd":"as","id":"submittedDiv","prop":"innerHTML","data":"Array<br \/>\n(<br \/>\n    [textBox1] => Here is some text.<br \/>\n)<br \/>\n"}]}

Re: value from xajax response object


Usually you don't mess with the returned data directly. In your php you you use the response object's member function to assign data to different elements, generate JS call JS, etc. The response is intercepted by the xajax JS code and the commands are processed.

The setReturnValue function is used to return a value to a synchronous server call.

var = xajax_function([params]);

The js code waits for the call to finish then does something with the returned value.

Here's a thread that may help: … urn-value/

Is there a particular reqson you want to do as you described?


If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: value from xajax response object

Thank you Edrobinson.

What I realy want is response from database update function. To that function I pass 3 parameters -- itemID, form data, action type (add, update, delete or select record).
If I use
        xajax_db_function(itemID, xajax.getFormValues("myForm"), action);

...I don't know how to get response from it (ad/update/delete succes/failure, or selected row data), so I looked in xajax/test folder for something that may suit my needs and tried to use this:

    xajax.request({xjxfun:'xajax_db_function'}, {
        [xajax.getFormValues('myForm'), '2'],
        onRequest: function() { alert('In inline onRequest'); },
        onComplete: function() { alert('In inline onComplete'); },
        onFailure: function(args) { alert('Failure -- status is: ' + args.request.status); }

...but it does not work.

So this is a common database task but I can't resolve it. My php function looks like this:

    function db_function($id, $data, $action)    {
           $response=new xajaxResponse();
    if ($action == 1) {
            // add record code
    } elseif ($action == 2) {
        $result = $tai_db->editTai($id, $data);
    } elseif ($action == 3) {
            // delete record code
        } elseif ($action == 4) {
            $result = $tai_db->getTai($id);
        return $response;