2010-07-03 172 views
0

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

这里的请求的代码:

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

该代码被从资源rb_wizard.js(行81-103)衍生于http://tylermorriswoodworking.myshopify.com/pages/recipe-box-wizard?b=maple&l=cherry&s=3x5&c=42042892

回答

0

我最终做的只是使用iframe。我真正必须做的是将数据发送到另一个网站,并没有收到任何结果。

1

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

因此,您粘贴的代码似乎位于antiradiant.com以外的域中,因此不允许(通过浏览器)请求antiradiant.com上的网站。

2

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