在页面重新加载之前显示的消息,在页面重新加载后不起作用

时间:2014-09-26 06:56:38

标签: javascript ajax

我有一个像下面这样的ajax响应代码

function click_delete_reply(){
    if ((ajMsgDel.readyState == 4) && (ajMsgDel.status == 200)) {
        var restxt = ajMsgDel.responseText;
        if (restxt == "success") {
            location.reload();
            display_messagesuccess(
                "Message Delete has been successfully performed!");
        }
    }
}

我需要在ajax响应成功后重新加载页面然后我需要在' div中写一条消息。但是在这里显示消息后,它只执行页面加载。我该怎么做才能克服这个问题?请帮帮我!

2 个答案:

答案 0 :(得分:1)

好的,好的,然后尝试一下这个。

在重新加载之前,请将一些参数附加到您的网址。有了这个,您可以在服务器端知道它是否是从您的ajax重新加载并返回一个更多的消息,如#34;重新加载"。然后你这样做:

$(function(){
   //if the param in url is called "reloaded"
   // then show message

});

$(函数(){});与#34相同; DOM准备就绪"

抱歉,我在公交车上,写不了多少。随意问。

答案 1 :(得分:0)

你应该做的是

1. Instead of Ajax Call give a server request and do the server side processing. 
a) If the job is done successfully just send the message as the request parameter. Read that message and display where ever you want. 
b) If the job fails then just return the values you need as response back to the page and display them where they should be.

由于每次加载页面时都会加载脚本,因此在重新加载页面后,您无法通过脚本消息显示消息。您可以显示消息,然后重新加载页面。或者按照我上面提到的方式行事。

相关问题