【问题标题】:MooTools Request FailingMooTools 请求失败
【发布时间】:2010-07-03 15:01:17
【问题描述】:

所以我有一点问题。当我要求 MooTools 发送请求时,它每次都返回失败。我似乎也无法诊断问题,因为如果我尝试获取返回的标头信息,控制台只会给我"Refused to get unsafe header 'Status'" 消息。我唯一能想到的是服务器不允许我访问外部资源,但也许我只是编码错误。

这是请求代码:

var finfo = current.textFontData();

var url = 'http://antiradiant.com/clients/TMW/rbwizard/mailer.php?s='+current.size+'&b='+current.box+'&l='+current.lidWood+'&c='+current.cartID+'&f='+finfo.font+'&l1='+finfo.line1+'&l2='+finfo.line2;
console.log(url);

var req = new Request({
    url: url,
    onSuccess: function() {
        console.log('success');
        //atc2.send();
    },
    onFailure: function() {
        console.log('failure');
        console.log(this.getHeader('Status'));
        //atc2.send();
    },
    onException: function(headerName, value) {
        console.log('exception');
        console.log(headerName+': '+value);
    }
});

req.send();

此代码源自 http://tylermorriswoodworking.myshopify.com/pages/recipe-box-wizard?b=maple&l=cherry&s=3x5&c=42042892 上的资源 rb_wizard.js(第 81-103 行)

【问题讨论】:

    标签: javascript ajax mootools xmlhttprequest


    【解决方案1】:

    Mootools 有一个名为 Request.JSONP 的类,可以帮助您解决跨域问题。它是 Request 类的子类,所以你的方法应该是一样的。我相信你需要在最后调用 .post() 或 .get() 而不是发送,但这就是所有应该改变的。我不确定你运行的是什么版本,但这里是他文档的链接Mootools Request.JSONP

    【讨论】:

      【解决方案2】:

      当您违反cross-domain security model 时,基于WebKit 的浏览器(Safari、Chrome 等)会吐出错误消息"Refused to get unsafe header 'Status'"

      因此,您粘贴的代码很可能位于 antiradiant.com 以外的域中,因此不允许(浏览器)请求 antiradiant.com 上的站点。

      【讨论】:

        【解决方案3】:

        我最终做的只是使用 iframe。我真正需要做的就是将数据发送到另一个站点并且没有收到任何数据,所以它成功了。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-04-07
          • 2017-04-02
          • 2014-01-31
          • 2020-11-26
          • 2021-02-16
          • 2018-11-30
          • 2012-10-02
          相关资源
          最近更新 更多