Skip to content Skip to sidebar Skip to footer

Parallel Ajax Calls - Fail To Receive Response From The First

I'm implementing a little 'ping' utility to check if our two servers are online. here is the javascript code: var t1, t2, t3, t4; function jsContactServers() { ajaxServerStatu

Solution 1:

You're falling prey to The Horror of Implicit Globals: You don't declare xmlhttp, so it's an implicit global, and so the call to ajaxServerStatusAPPS overwrites the value that the call to ajaxServerStatusWWW stored in that variable. Both functions try to use the same variable.

Within ajaxServerStatusWWW and ajaxServerStatusAPPS, declare the variable using var so they each have their own.

On modern browsers, you can make doing this an error rather than an implicit global by using "strict" mode. When you assign to an unknown identifier in strict mode, it causes a ReferenceError rather than creating a global.

Post a Comment for "Parallel Ajax Calls - Fail To Receive Response From The First"