简体   繁体   English

使用 JavaScript 重新加载页面(在 jquery ajax 请求内)

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

my question is, what I have to do to reload a page with javascript.我的问题是,我必须怎么做才能用 javascript 重新加载页面。 I have written the following function:我写了以下 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:问题是,ajax 请求成功,结果是一个 json 对象:

{"status":"200"}

But the window doesn't reload.但是 window 不会重新加载。 If I use the this line如果我使用这条线

window.location.reload()

at firebug and execute it, the browser window reloads.在萤火虫并执行它,浏览器 window 重新加载。

What could be the problem?可能是什么问题呢? Thanks in advance.提前致谢。

Try changing the data type to JSON:尝试将数据类型更改为 JSON:

dataType: "json"

You have a syntax error end of window.location.reload() .您有window.location.reload()的语法错误结尾。 Add semicolon after this line and try again.在此行后添加分号,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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