0

my question is, what I have to do to reload a page with javascript. I have written the following function:

  function update(id, name)
    {
    if(/^\d+$/.test(id))
    {
        $.ajax({
            url: baseurl + "/url/action/param/" + id + "/param2/" +  unescape(name),
            success: function(data) {
                $("#overlay").fadeOut().remove();
                if(data.status == '200') {
                  window.location.reload()
                }
                else if(data.error) {
                    $("#messages").html(data.error).fadeIn();
                }
            },
            type: "GET",
            dataType: "text"
        });
    }
    else
    {
        return false;
    }
}

The problem is, that the ajax-request is successfull, the result is a json-object:

{"status":"200"}

But the window doesn't reload. If I use the this line

window.location.reload()

at firebug and execute it, the browser window reloads.

What could be the problem? Thanks in advance.

  • Are you sure you need to reload? Why would you need to reload. Is there an issue you solve by reloading that may be solved differently? – mplungjan May 03 '11 at 11:09

2 Answers2

0

Try changing the data type to JSON:

dataType: "json"
Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194
-1

You have a syntax error end of window.location.reload() . Add semicolon after this line and try again.

Çağdaş
  • 963
  • 1
  • 11
  • 32