Welcome, Guest. Please login or register.
Did you miss your activation email?
Feb. 09, 2010, 03:33:37 PM
52593 Posts in 11677 Topics by 7491 Members
Latest Member: peerjee
News: New to PRADO? The PRADO blog tutorial is a good start point.
 
The PRADO Community » Prado v3.x » Bug Reports » [PATCH AVAILABLE] Multiple Ajax Requests with Parameters Appears to be Buggy « previous next »
Pages: [1] Print
Author Topic: [PATCH AVAILABLE] Multiple Ajax Requests with Parameters Appears to be Buggy  (Read 779 times)
Doublespeak
Junior Member
**

Karma: 6
Offline Offline

Posts: 15


View Profile
« on: Oct. 16, 2009, 08:42:21 AM »

Hi folks,

I'm a long time lurker, part time poster here - have been having a nasty issue to do with dispatching Ajax requests.
Note that I am using asynchronous Ajax requests here.

Given the code in a .page:
Code:
<script language="javascript" type="text/javascript">
function performActionOnObjectID(objectID, actionType) {
                var request = <%=$this->callbackAction->ActiveControl->Javascript %>;
request.setCallbackParameter({'action':actionType, 'id':objectID});
request.dispatch();
        }
</script>

<com:TCallback ID="callbackAction" OnCallback="callback_Action" EnableViewState="true">
</com:TCallback> 

<a href="javascript:performActionOnObjectID(27,'approve');">approve 27</a><br />
<a href="javascript:performActionOnObjectID(28,'approve');">approve 28</a><br />
<a href="javascript:performActionOnObjectID(29,'approve');">approve 29</a> <br />
<a href="javascript:performActionOnObjectID(30,'approve');">approve 30</a> <br />
<a href="javascript:performActionOnObjectID(31,'approve');">approve 31</a> <br />
<a href="javascript:performActionOnObjectID(32,'approve');">approve 32</a> <br />
<a href="javascript:performActionOnObjectID(33,'approve');">approve 33</a> <br />
<a href="javascript:performActionOnObjectID(34,'approve');">approve 34</a> <br />
<a href="javascript:performActionOnObjectID(35,'approve');">approve 35</a> <br />
<com:TJavascriptLogger />

I would expect the output in my Javascript logger or Firebug to show the ID# passed in the "performActionOnObjectID" - ie. one of 27, 28, 29, etc, given the following handler (.php):
Code:
public function callback_Action($sender, $param)
{
$theAction = '';
$theID = -1;

if ($param->CallbackParameter)
{
if ($param->CallbackParameter->action)
{
$theAction = $param->CallbackParameter->action;
echo "THE ACTION=".$theAction;
}
if ($param->CallbackParameter->id)
{
$theID = intval($param->CallbackParameter->id);
echo "THE ID=".$theID;
}
}
}               

Most of the time the ID number of the link I clicked on in the .page appears in my logger/firebug - BUT SOMETIMES, SOMETHING GOES REALLY WRONG!

When you click on ALL of the links only ONCE (27 through to 35), one after the other as quickly as possible, the Ajax queue "enqueues" each of the ajax callback requests, and sends them off sooner or later. But instead of the debug output in my logger/firebug showing something like 27,29,35,32 etc (ie. each ID number only once), often it will show a result like 27,28,35,35,35,35 etc.

It appears that the queued callbacks after the first two or three ajax requests have their parameters overwritten in memory (on the client side I suspect - perhaps within ajax3.js or activecontrols3.js) which causes the above behaviour to take place.

Has anyone else noticed this issue? Even though i am running PRado 3.1.2 i have checked the svn repo and not much appears to have changed in ajax3.js or activecontrols3.js)

A desperate dilletente awaits your assistance!

-Damo







« Last Edit: Oct. 19, 2009, 05:43:03 AM by Doublespeak » Logged
Doublespeak
Junior Member
**

Karma: 6
Offline Offline

Posts: 15


View Profile
« Reply #1 on: Oct. 19, 2009, 05:50:45 AM »

I've written a patch for this issue - and have tested it on my development server. (works well)

Since I don't know how to create a diff (And I'm running a slightly older version of PRADO - 3.1.2) I'll just describe the changes you need to make to apply this patch. (can somebody please put this into the trunk for me?)

ajax3.js, located in framework/Web/Javascripts/source/activecontrols/:
Quote
   initialize : function(id, options)

   {

      /**

       * Callback URL, same url as the current page.

       */

      this.url = this.getCallbackUrl();

      this.transport = Ajax.getTransport();

      this.Enabled = true;

      this.id = id;

      this.randomID = this.randomString();

      if(typeof(id)=="string"){

         
         Prado.CallbackRequest.requests[id+"__"+this.randomID] = this;

      }

.....


      this.ActiveControl = this.options;
      Prado.CallbackRequest.requests[id+"__"+this.randomID].ActiveControl = this.options;

   }

further down, in ajax3.js:
Quote
   setCallbackParameter : function(value)

   {

      this.ActiveControl['CallbackParameter'] = value;
      var theID = this.id+"__"+this.randomID;
      Prado.CallbackRequest.requests[theID].ActiveControl['CallbackParameter'] = value;


   },
   randomString : function() //thanks to The JavaScript Source!! http://javascript.internet.com/passwords/random-password-generator.html
   {
     var length = 8;
     chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
     theString = "";
     for(x=0;x<length;x++)
     {
       i = Math.floor(Math.random() * 62);
       theString += chars.charAt(i);
     }
     return theString;
   },


and further down in ajax3.js:
Quote
   getCallbackParameter : function()

   {

      return this.ActiveControl['CallbackParameter'];
      return Prado.CallbackRequest.requests[this.id+"_"+this.randomID].ActiveControl['CallbackParameter'];
   },


and last but not least in ajax3.js:
Quote
   _getPostData : function()

   {

......

if(typeof(this.ActiveControl.CallbackParameter) != "undefined")

         data[callback.FIELD_CALLBACK_PARAMETER] = callback.encode(this.ActiveControl.CallbackParameter);
         data[callback.FIELD_CALLBACK_PARAMETER] = callback.encode(this.getCallbackParameter());
......

        }

Had a hell of a time getting this working - please tell me if you find it useful or have put it into the SVN/CVS.

Thanks,

-Damo.
« Last Edit: Oct. 19, 2009, 06:04:53 AM by Doublespeak » Logged
rojaro
Global Moderator
Platinum Member
****

Karma: 36
Offline Offline

Posts: 620


PRADO aint no voodoo ...


View Profile WWW
« Reply #2 on: Nov. 01, 2009, 09:29:04 PM »

Niiiiiice Smiley
Merged in r2727.
Karma++

Greetings from Rostock / Germany
- rojaro -
Logged

A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Doublespeak
Junior Member
**

Karma: 6
Offline Offline

Posts: 15


View Profile
« Reply #3 on: Nov. 02, 2009, 12:05:40 AM »

Thanks rojaro - much appreciated! I really need to learn how to create a diff Smiley

Cheers,

-Damo
Logged
rojaro
Global Moderator
Platinum Member
****

Karma: 36
Offline Offline

Posts: 620


PRADO aint no voodoo ...


View Profile WWW
« Reply #4 on: Nov. 02, 2009, 12:41:03 AM »

Well ... if your next patch is as good as this one, i don't really care whether it comes as diff or not. However, diff -Naur oldfile newfile > patchfile is your friend ;-)

Greetings from Rostock / Germany
- rojaro -
« Last Edit: Nov. 02, 2009, 12:43:55 AM by rojaro » Logged

A mathematician is a machine for turning coffee into theorems. ~ Alfred Renyi (*1921 - †1970)
Pages: [1] Print 
« previous next »
Jump to: