H_MZ 2014-06-05 09:04 采纳率: 0%
浏览 20

没有push.js的Ajax请求

I'm using Ratchet 2 to build an app. I'm trying to make a simple ajax call and get the response like so

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);

}

When I click on my button that fire tryLogin() the ajax call is well executed but the page is reloaded. I assume that it is from push.js

Is there any solution to ignore push.js on an ajax call ?

  • 写回答

2条回答 默认 最新

  • 七度&光 2015-03-03 13:20
    关注

    Have you tried putting the data-ignore="PUSH" attribute on the button that is firing your javascript event? Seems like that should work, you may also be able to look at PUSH.js and just toggle that options off for your request. You can get the PUSH object from Window.Ratchet.push.

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

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题