在进行两次ajax调用后刷新页面时出现问题

时间:2010-11-13 15:41:16

标签: javascript ajax yahoo

问题我正在对server1进行ajax调用,即csce,一旦得到响应,我将响应作为内容发送到server2 ieyahoo服务器后得到响应,我想刷新页面或至少将其重定向到同一页面。这两个ajax调用都运行正常。我发送的内容也保存了唯一的问题是我必须手动刷新页面才能看到更改。我想在内容保存在雅虎后刷新页面。我在yahoo的成功功能中尝试了重新加载重定向命令。但没有任何作用。我可以在HTTPfox中看到两个ajax调用,但不能看到重定向。

我正在拨打电话的网址与保存内容的网址不同,这就是为什么我需要刷新页面才能看到更改。即我在发送内容并在yahoo / edit上看到更改时保存在yahoo / save中。

我不确定我哪里出错了。这是我正在使用的代码。任何人都可以建议我哪里出错了。如果我的问题不明确,那么请让我澄清一下。感谢。

此代码是代码:

 function handleButtonClick()
{
// Declare the variables we'll be using
var xmlHttp, handleRequestStateChange;

   // Define the function to be called when our AJAX request's state changes:
handleRequestStateChange = function()
{
    // Check to see if this state change was "request complete", and
    // there was no server error (404 Not Found, 500 Server Error, etc)
    if (xmlHttp.readyState==4 && xmlHttp.status==200) 
    {
        var substring=xmlHttp.responseText;

        alert(substring);// I am able to see the text which is returned by the server1 i.e csce
var handleSuccess = function(o)
 {
   if(o.responseText !== undefined)
   {
     console.log(o.responseText);
 **window.location.reload()** // also I tried to redirect it to the same site but that also not works


  }
 };
var callback ={ success:handleSuccess,  failure: function(x) {
console.error(x) }, argument: ['foo','bar']};
var request = YAHOO.util.Connect.asyncRequest('POST','http://yahoo.com******', callback, substring);

    }
}

xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://cse*****id=c6c684d9cc99476a7e7e853d77540ceb", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
 }

2 个答案:

答案 0 :(得分:2)

您是否只想在页面中显示内容?为什么不尝试document.getElementById('divID').innerHTML = xmlHttp.responseText;

的内容

divID是您要用其填充内容的div的ID。

答案 1 :(得分:0)

handleRequestStateChange函数

中尝试关注
window.location.href = window.location.href;
相关问题