简体   繁体   中英

Reload a page with JavaScript (within jquery ajax-request)

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.

Try changing the data type to JSON:

dataType: "json"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM