# Other Languages > XML, HTML, Javascript, Web and CSS >  [RESOLVED] Another JavaScript issue, code in if block

## DataMiser

I have the bit of code below that is not behaving as I expected.


```
function StatusSet(req){
		if (req.status == 200) {	
			$("#scrmsg").html("");
			var arr = new Array();
			var response = req.responseText;
			arr = response.split("~|~");
			if (arr[0]==0){			
				window.location.reload();
			}else{
				$("#scrmsg").html(arr[1]);
				return;	
			}			
		}else{
			$("#scrmsg").html('Call to server failed. Error='+req.status);
		}		
	}
```

I am sending the data back so that arr[0] is not = 0 and arr[1] contains a message that should be displayed on screen.
If I comment out the window.location.reload(); line then I see the message as expected.
If  that line uncommented then the page reloads and the message is not seen.

Any idea why it is executing the page reload when arr[0]==0 is false?

----------


## jpbro

What do you see if you put 



```
alert(arr[0]);
```

in place of window.location.reload()?

What happens if you use 



```
if (arr[0]===0 ){
```

in place of if (arr[0]==0 ){?

----------


## DataMiser

Interesting. It appears that code is executing more than once. In some cases anyway. I'll have to dig deeper, maybe something else is going on.

----------


## DataMiser

hmm very odd. I simplified the code a bit as a test. Got rid of the array and just used a plain string which contains either "OK" or some message to be displayed.
Using basically the same block of code as posted it seems to work as expected.

When using the previous code and placing an alert box in there I would see that block execute once showing arr[0] as empty then it would execute again and show it with a value.
The expectation was that it should execute only once and always have a value then behave according to the value of said value but it appears there may be some eels in that hover craft  :Wink:

----------


## DataMiser

Well I'm still not sure why it was not working with the array and the 0 in the first element but as it turns out using the string should be enough in this case so I will mark this one resolved and move on to the next potential problem.

----------


## DataMiser

Update: It appears that the root of the problem was me failing to check the ready state. The function was firing before the array was populated and then firing again after it was populated. Still weird that it executed the code inside the conditional when the array element was empty but it seems to work fine after adding the test of the ready state in there.

----------

