tags:

views:

73

answers:

3
var act = false;
var newprod = prompt("tell me somthing", "");

if (newprod != '' && newprod != null) {
  $.ajax({
    //posting code here
  });
}

if (act != false) { document.location.href = window.location; }

The page is refresh in every condition even act false or not.

It is fired on an event.

Can anyone tell me why it page is refreshed in all condition?

A: 

This should work

if( newprod != null && newproda.length != 0) {

 //Execute the code

}

To the reason why it was always working was that newprod was not the same as ''.

As the question is what is wrong with that JavaScript code i will advise.

if(act) {
 document.location.href = window.location;
}
Vash
A: 

You may want to learn more about false-y values in JavaScript. My guess is that your if statement is giving you some problems because it does not compare the way you think it should compare.

JasCav
+1  A: 
var act = false;
var newprod = prompt("tell me somthing", "");

if (newprod) { // not null, undefined or 0
  $.ajax({
    //posting code here
  });
}

if (act) { window.location.reload(1); }

assuming that is what the code was supposed to do. document.location is deprecated and in theory read-only.

mplungjan