2014-06-05 96 views
1

我使用Ratchet 2來構建應用程序。我試圖做一個簡單的Ajax調用,當我點擊我的按鈕火災tryLogin() Ajax調用很好地執行,但重新加載頁面得到像這樣Ajax request without push.js

function tryLogin() { 
var hxr; 

if (window.XMLHttpRequest) { 
    xhr = new XMLHttpRequest(); 
} else { 
    xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
} 

xhr.open("POST", "absolutePathToMyScript"); 
xhr.onreadystatechange = function() { 
    if (xhr.readyState == 4) { 
     var obj = JSON.parse(xhr.responseText); 
     console.log(obj); 
     //spinner.classList.remove("active"); 
    } 
} 

var data = { 
    login: document.querySelector('#loginForm input[name="login"]').value, 
    pwd: document.querySelector('#loginForm input[name="pwd"]').value 
}; 

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
xhr.send("login=" + data.login + "&pwd=" + data.pwd); 

}

的響應。 我認爲它是從push.js

有沒有解決方案忽略ajax調用push.js?

回答

0

您是否曾嘗試在觸發您的javascript事件的按鈕上放置data-ignore =「PUSH」屬性?似乎應該可以工作,您也可以查看PUSH.js,並根據您的請求切換該選項。您可以從Window.Ratchet.push中獲取PUSH對象。

http://goratchet.com/components/#push

0

Ratchet.js將您的網站變成一個單頁的應用。我認爲你有一個表單域內的輸入,當按鈕被點擊時這會導致一個帖子,這是一個意外的頁面導航。如果是這種情況,解決辦法是在你的onclick事件處理函數返回false

button onclick="tryLogin();return false;">Try Login</button> 

example