Topic: JS to xajax: direct communication

Hi folks,

I try to write a JS-xajax connection and don't know how, so please help me if you can.
I want to do the following (JS):

function checkValues(value1, value2)
{
  if (xajax_check(value1, value2) == true)
  {
     /* do something */
  }
}

Simply as it looks, it doesn't work because I can't find a method to send a variable value (TRUE or FALSE in this case) back to the point in javascript where I called xajax.

Anyone smarter than me who can tell me if this is possible and if yes: how?

Thanks,
       Creativebyte

Re: JS to xajax: direct communication

I think the problem here is that ajax / xajax is asynchronous. Once checkValues calls xajax_check it's done. Then your'e at the mercy of the client side xajax object to send the xmlhttp thing to the server and handle the return in its callback handler.

I think you could write a second piece of JS and have the response object use the addScriptCall method to invoke it.  The second JS function does whatever you wanted to do in checkValues.

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

Re: JS to xajax: direct communication

Hi,

I thought about the hole mess and I had a look at the xajax sourcecode and it seems that your way is the only way possible. So I have to rewrite the hole thing and mount the horse from the other side.
Thanks,

Creativebyte

Re: JS to xajax: direct communication

CreativeByte,

Actually, synchronous xajax calls are possible, however, you need to get xajax 0.5 beta 2 from SVN.  I've added the following to make it work:

(javascript):

var result = xajax.call('myPHPFunction', { mode: 'synchronous', parameters: [ xajax.$('checkBoxOne').checked, xajax.$('checkBoxTwo').checked ] } );
if (result) {
    /* do something */
}

(PHP):

function myPHPFunction($checkBoxOne, $checkBoxTwo) {
    $objResponse = new xajaxResponse();
    $objResponse->setReturnValue("OK");
    return $objResponse;
}

We are working toward a beta 2 release.  If for some reason you are not able to get the code from SVN, email me and I can send you a .zip'd copy.

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct

Re: JS to xajax: direct communication

Great! I'll try that first thing monday morning. Semms like I finally switch to 0.5, since I use 0.2.4 up to now.
Thanks fpr the help CtC, keep up the good work :-)

I wil write here to share my experiences...

Creativebyte

Re: JS to xajax: direct communication

That is a piece of good news. I too have wanted do be able to some synchronous calls and have had to resort to the method I explained.

Great! smile

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

Re: JS to xajax: direct communication

dont work for me.. sad only return false... :S im using a 0.5 RC1.. .:S why dont work.. ??