1 (edited by dsta 2010-04-22 12:10:30 PM)

Topic: Multiple XAJAX-Calls in a Row *HELP*

Hi,

I am developing something like 'Twitter'. It works fine in general, but I have got a question for the experts here smile

On the Site there is a Inputbox on top and the messages are displayed under it. Now if someone posts a new text, I have to call the xajax-function "do_tweet". After this function is done I need to refresh the posted messages to display the message posted a secound ago! The function zu refresh this is "display_tweets".

My first try was to do it simply with Javascript...

<form name="ftweet" onsubmit="xajax_do_tweet(ftweet.text.value);xajax_display_tweets(ftweet.text.value);return false;">

I took a look at the xajax-debug-output, it seems that the 2 xajax-requests are startet simultaneous and not in a row :-( So it happens sometimes that the new message is not displayed becouse the refresh was faster then the post-function :-(

Is there any way to do this?

Thu Apr 22 13:06:41 UTC+0200 2010
CALLING: xjxfun: display_tweetsURI: http://localhost/twitter/

Thu Apr 22 13:06:41 UTC+0200 2010
POST: xjxfun=display_tweets&xjxr=1271934400964&xjxargs[]=Shallo

Thu Apr 22 13:06:40 UTC+0200 2010
PREPARING REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
PROCESSING PARAMETERS [1]

Thu Apr 22 13:06:40 UTC+0200 2010
INITIALIZING REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
STARTING XAJAX REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
SENT [51 bytes]

Thu Apr 22 13:06:40 UTC+0200 2010
SENDING REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
CALLING: xjxfun: do_tweetURI: http://localhost/twitter/

Thu Apr 22 13:06:40 UTC+0200 2010
POST: xjxfun=do_tweet&xjxr=1271934400308&xjxargs[]=Shallo

Thu Apr 22 13:06:40 UTC+0200 2010
PREPARING REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
PROCESSING PARAMETERS [1]

Thu Apr 22 13:06:40 UTC+0200 2010
INITIALIZING REQUEST

Thu Apr 22 13:06:40 UTC+0200 2010
STARTING XAJAX REQUEST

Re: Multiple XAJAX-Calls in a Row *HELP*

Hi,

ajax is asynchronous so it is hard to predict the order of things.

You do not need to make 2 calls to the server. You can run both functions in th same call using the response object's loadCommands() function.

function do_tweets($tweet)
{
   $resp = new xajaxResponse();
   ...
   $resp->loadCommands(display_tweets($tweet));
   return $resp;
}

function display_tweets($tweets)
{
   $resp = new xajaxResponse();
   ...
   return $resp;
}

Hope this helps.

Ed

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

Re: Multiple XAJAX-Calls in a Row *HELP*

Yes, thats all I need, I tried this, but I didn`t know the Command :-) This is to "Merge" two Response-Object, thats allmost perfect for what I am doing smile

Greetings & Thank you
Dominik