2010-11-13 55 views
0

問題我提出AJAX調用到Server1即歐安會,一旦我得到的迴應我發送響應爲內容,以獲得響應之後,Server2上ieyahoo服務器從那裏我想刷新頁面或至少將其重定向到同一頁面。兩個Ajax調用都正常工作。我發送的內容也保存唯一的問題是,我必須手動刷新頁面才能看到更改。一旦內容保存在雅虎,我想刷新頁面。我試過重新加載重定向命令成功功能雅虎。但沒有任何工作。我可以在HTTPfox中看到這兩個Ajax調用,但不是重定向。問題需要

我打電話的URL與保存內容的網址不同,這就是爲什麼我需要刷新頁面才能看到更改。即我在yahoo/save中保存,同時發送內容並查看yahoo/edit中的更改。

我不知道我哪裏出錯了。這是我使用的代碼。任何人都可以建議我去哪裏錯了。如果我的問題不明確,請問我澄清更多。謝謝。

此代碼是代碼:

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

你只是想顯示在你的頁面內容?你爲什麼不嘗試沿着document.getElementById('divID').innerHTML = xmlHttp.responseText;的方向走?

divID是您想要填充內容的div的ID。

+0

是的,如果你正在使用AJAX,使用它。不要重新加載您的頁面,只需重新填充您的內容區域。 – aptwebapps 2010-11-13 16:06:42

+0

感謝克里斯和aptwebapps ::我想刷新頁面看到的變化,因爲網頁有不同的URI比我在哪裏保存。而且我無法控制這些變化。我想要顯示給用戶的更改只是刷新頁面。然後它會自動顯示圖片。你能建議任何其他的出路嗎? – Judy 2010-11-13 19:44:54

+0

如果你想在一個單獨的頁面上的內容,你將不得不通過cookie,會話變量,數據庫等以某種方式傳遞數據。如果你使用AJAX和刷新,這是有點擊敗目的。任何可以詳細說明的內容都可以幫助您更清楚地瞭解自己正在做的事情。 – 2010-11-13 22:39:35

0

嘗試在handleRequestStateChange功能如下

window.location.href = window.location.href;