MooTools JSONP 请求不适用于无效密码
我使用 MooTools 发出 JSONP 请求:
var username = 'hsz';
var password = 'pass';
var req = new Request.JSONP({
url: 'http://api.blip.pl/profile.json',
method: 'get',
headers: {
'Authorization' : 'Basic ' + Base64.encode(username + ':' + password),
'Accept' : 'application/json',
'Content-Type' : 'application/json',
'X-blip-api' : '0.02'
},
onSuccess: function(res){ alert('success'); },
onFailure: function(res){ alert('failure'); }
}).send();
使用有效的登录名和密码,它可以正常工作(提醒我成功
)。
当我将密码
更改为无效值时,它不会执行任何操作。
我不知道为什么它表现得很糟糕。
当我使用 Request.JSON()
时也是如此。 有什么想法吗?
I make a JSONP request using MooTools:
var username = 'hsz';
var password = 'pass';
var req = new Request.JSONP({
url: 'http://api.blip.pl/profile.json',
method: 'get',
headers: {
'Authorization' : 'Basic ' + Base64.encode(username + ':' + password),
'Accept' : 'application/json',
'Content-Type' : 'application/json',
'X-blip-api' : '0.02'
},
onSuccess: function(res){ alert('success'); },
onFailure: function(res){ alert('failure'); }
}).send();
With valid login and password it works fine (alerts me success
).
When I change password
to an invalid value it does not do anything.
I do not know why it behaves badly.
Same thing when I use Request.JSON()
.
Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能是服务没有响应任何内容,因为它无法验证/授权请求,只是为了在密码或用户 ID 或两者都错误时留下任何黑客!
May be service is not responding with anything whey it cannot authenticate/authorize the request just to leave any hacker if password or user id or both are wrong!
我认为 onFailure 只是 Request 类在 XHR 请求中失败时触发的事件。如果您无法进行身份验证,并不意味着它无法触发 Request 实例,只是无法获得预期的结果。
在 1.2.4.x 中,request.jsonp 支持可选日志(实现的控制台包装类日志) - 将 log: true 添加到类选项中,并查看它尝试在 firebug 中引发哪些事件。
另外,您可以将处理程序更改为 onComplete 并插入返回的 json,以根据数据确定其成功程度(与 onSuccess 相反)
i think the onFailure is simply the event fired by the Request class when it fails in the XHR request. if you fail to authenticate it won't not mean it failed to fire the Request instance, just failing to get the expected results.
in 1.2.4.x, request.jsonp supports optional log (implemented console wrapper class log) - add log: true to the class options and see what events it tries to raise in firebug.
also, you can change the handler to onComplete and interpolate the json returned to determine how successful it has been based upon the data (as opposed to onSuccess)
JSONP 类有一个超时属性。默认设置为0并且onFailure不被触发。
我设置了 timeout:1 现在 onFailure 被触发。
At the JSONP class there is a timeout property. By default is set to 0 and onFailure was not triggered.
I set timeout:1 and now onFailure is triggered.