Topic: XAJAX ····(data)····> PHP

JS (JavaScript) is synchronous and asynchronous. PHP is synchronous. Ok. 

PHP is executed by the server. JS is executed by the client. Ok.

PHP executed first. JS executed after. Ok.

Well. Is possible that I send data with XAJAX and PHP get it?

PROBLEM: I would like to know that an user (a client that load my web site) has javascript activated or not (ALERT! JS activated and JS supported are not the same)

I thank to send a variable (data) with XAJAX and PHP gets it.


  client                    server
-----------            ------------
- XAJAX - ············> -   PHP   - 
-----------            ------------

XAJAX sends a string, for example, "JS is activated", and PHP gets this string with a variable, and I process this result: launch a page performed for javascript or launch a page performed for without javascript. 

The problem is when the page loads, PHP is executed one time. When all PHP code finish execution, if XAJAX (asynchronous JS mode) sends data, ¿how catch this data?

All of that I previous write in this post summarizes in one question: PHP has a asynchronous mode?

Thanks for all. Greetings.

Last edited by vieiras (2009-08-06 6:54:07 PM)

Re: XAJAX ····(data)····> PHP

Hi,

I'm not sure I fully understand but...

ajax uses the XmlHttp object. XAJAX is a framework around it to make life easier...

A page that uses XAJAX instances the xajax object, registers one or more functions that the page needs to recognize then calls the xajax processRequest() method.

The processRequest method traps calls to your registered functions and calls them passing any appropriate parameters.

Your registered function instances the xajax response object, calls its methods and returns it.

The processRequest method now interprets the commands you added to the response object and formats them for the browser side xajax JS as XML and returns it to the browser.

So, while PHP has no asynchronous mode, xajax provides the tools to make it appear asynchronous.

Of cource, if the caller has JS disabled, there can be no XAJAX traffic...

Take a look at the samples that come with the XAJAX download. They clarify things pretty well.

Hope this helps... smile

Ed

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