Hi,

You're rescheduling the function right away without waiting for the
Ajax call to complete.  I can't say I've seen that specific error, but
if the call takes more than a second (which is perfectly likely),
you'll start getting things stacking up quite quickly.  If you move
your rescheduling `setTimeout` call into the onComplete callback,
it'll get scheduled for a second after the last call completed, which
is probably more appropriate.

There are some other things you might consider:

1. Using the onSuccess callback rather than onComplete. onComplete is
appropriate for your rescheduling call, but onSuccess is where you
should be updating the div.

2. Using `String#startsWith`[1] rather than a regex to match "Error"
at the beginning of the response text, since the matching isn't
complicated.

[1] http://prototypejs.org/api/string/startsWith

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 25, 7:52 pm, sddeals <yuanmi...@gmail.com> wrote:
> What I'm trying to do is let the page make ajax request every second
> to get the latest status from ajax.php however I got a "too much
> recursion" error in the javascript. Any ideas? Thanks a lot!
>
> <script type="text/javascript">
> function displayMSAStatus()
> {
>
>         var url="Ajax.ashx";
>         var params="do=MSAStatus";
>         var myAjax = new Ajax.Request
>         ( url,
>
>             {
>                 method: 'get',  parameters: params ,
>                         onComplete: function(response)
>                         {
>                             var el = document.getElementById('MSAStatusDiv');
>
>                             var re = /^Error/;
>
>                             if (!response.responseText.match(re))
>                             {
>                                         el.innerHTML = response.responseText;
>
>                                 }
>
>                 }
>         }
>         );
>
>         setTimeout(displayMSAStatus, 1000);
>
> }
>
> setTimeout(displayMSAStatus, 1000);
>
> </script>
> <div id=MSAStatusDiv>
> </div>
>         setTimeout(displayStatus(vthis), 1000);
>
> }
>
> displayStatus(document.getElementById('statusDiv'));
>
> </script>
> <div id=statusDiv>
> </div>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to