2014-09-26 150 views
0

我有这样的一个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'中的消息。但在这里显示消息后,只有它执行页面加载。我能做些什么来克服这一点?请帮帮我!

+0

因为您的js在reload()之后不再运行,所以您无法在页面重新加载后编写消息。 – doniyor 2014-09-26 07:01:29

+0

那么我该如何解决这个问题哥们? @ doniyor – androidGenX 2014-09-26 07:02:16

+0

为什么不先显示消息然后重新加载?顺序没有什么不同,因为你的ajax工作成功了。 – doniyor 2014-09-26 07:05:12

回答

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. 

。您可以显示消息然后重新加载页面。或者按照我上面提到的方式进行。

+0

不能做伙计,因为它在不同的基础上工作!我该如何克服这一点?有任何想法吗?? – androidGenX 2014-09-26 07:10:21

+0

你可以像'?msg = This-is-message'一样传递一个参数。然后在UI上显示此消息 – 2014-09-26 07:14:07

1

好的,很好,然后尝试一些喜欢这个。

重新加载之前,将一些参数附加到您的网址。有了这个,你可以在服务器端知道它是否是从你的ajax重新加载,并像“重新加载”一样返回一个msg。然后你这样做:

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

}); 

$(function(){});与“DOM已准备好”相同

对不起,我在公交车上,无法写多少。随意问。