2

i have a problem while making an ajax request using xajax. The issue is that i dont want to start the session on the server unless it is completely necessary. For an xajax call, the response can not be send without the existance of the session, so i am forced to start it.

So, assuming that session is not started in the moment where the user makes the call from the client side, if i have this function on the server side:

function example() {
    $response = new XajaxResponse();
    $response->script("alert('hello')");
    return $response;
}

I get an error. I can not trace the error in chrome or explorer, but in firefox i get an uncaught object exception in the core of the library. If i start the session before making the return, it "works":

function example() {
    session_start();
    $response = new XajaxResponse();  
    $response->script("alert('hello')");
    return $response;
}

I say "works" because it works in a partial way. In firefox the ajax call goes through perfectly, however in chrome/ie i need to make 2 calls: the first time nothing happens, while the second is ok.

The only solution i can think now is a very dirty one. It should be to create an xajax function to start the session:

function startSession () {
     session_start();
}

And then, from the client side make two calls in this way:

xajax_startSession(); xajax_example();

With this approach i solve the problem of "first execution" in chrome/ie, but is a very bad idea to have to add an extra call to every single xajax call :(

Thanks a lot again for your help

yauros
  • 157
  • 1
  • 3
  • 8

2 Answers2

2

and you can do the same action with

$response->alert('hello');

instead of

$response->script("alert('hello')");

good luck

1

You code is wrong, unless you just wrote it on the fly

function example() {
    session_start();  
    $response->script("alert('hello')");
    $response = new XajaxResponse();
    return $response;
}

The two lines should be switched

    $response->script("alert('hello')");
    $response = new XajaxResponse();

As for your actual question it seems like a repeat of Create the session during ajax call (php-xajax)

Community
  • 1
  • 1
Louis Ricci
  • 20,804
  • 5
  • 48
  • 62
  • Sorry yes, i made a mistake with the copy-paste. I continued with the previous question but a user suggested me to open a new topic. It's not exactly the same – yauros Oct 16 '12 at 14:18