- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我这里发生了一些非常奇怪的事情。我有一个正在尝试获取的模型。我可以查看 Fiddler 中的调用或手动调用我的 API 服务,我得到了我期望返回的 JSON,但 fetch 方法总是在 Backbone 中引发错误。它没有告诉我原因并且 responseText 是空的。在 fiddler 中,服务返回 200。
这是调用代码...
this.createSession = function (sessionId) {
var that = this;
CookieManager.CreateSession(sessionId);
var sessionData = new Authentication.Response({
id: sessionId
});
sessionData.fetch({
success: function () {
that.storeData(sessionData);
},
error: function (model, xhr) {
if (console !== undefined && console !== null) {
console.log('Unable to load session data: ' + xhr.responseText);
}
throw new Error('Unable to load session data');
}
});
};
以及相关的模型...
define(['ministry', 'moment'],
function (Ministry) {
var authRequest = Ministry.Model.extend({
name: 'Auth Request',
urlRoot: '/api/auth',
defaults: {
id: undefined,
requestSource: undefined,
apiKey: undefined,
username: undefined,
password: undefined,
dateCreated: undefined,
lastLoggedIn: undefined
},
generatedHash: undefined,
parse: function(attributes, response) {
var hashUrl = response.xhr.getResponseHeader('location');
var elements = hashUrl.split("/");
this.generatedHash = attributes.id = elements[elements.length - 1].toLowerCase();
return attributes;
},
validate: function (attributes) {
if (attributes.requestSource === undefined || attributes.requestSource == null || attributes.requestSource == '') {
return "The attribute 'requestSource' is required";
}
if (attributes.apiKey === undefined || attributes.apiKey == null || attributes.apiKey == '') {
return "The attribute 'apiKey' is required";
}
if (attributes.username === undefined || attributes.username == null || attributes.username == '') {
return "The attribute 'username' is required";
}
if (attributes.password === undefined || attributes.password == null || attributes.password == '') {
return "The attribute 'password' is required";
}
return null;
}
});
// Return as two types for syntactic sugar reasons.
return {
Request: authRequest,
Response: authRequest
};
});
该模型扩展了我的通用根模型,其代码在此处...
var ministryModel = Backbone.Model.extend({
name: 'Unnamed Model',
initialize: function (options) {
this.options = options || {};
Backbone.Model.prototype.initialize.call(this, options);
if (this.options.name) {
this.name = this.options.name;
}
this.on('invalid', function (model, error) {
if (console !== undefined) {
console.log(error);
console.log(model);
}
throw (new Error(error));
});
},
fetch: function (options) {
this.trigger('fetching', this, options);
return Backbone.Model.prototype.fetch.call(this, options);
}
});
总是调用错误回调,我不明白为什么。在 Fiddler 中,我通过直接调用 API 获得以下信息...
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 19 Aug 2013 16:12:00 GMT
Content-Length: 213
{"id":"bba5e742d1af3de5921e8df0a1818530789c202a","dateCreated":"2013-07-22T17:57:20.143","lastLoggedIn":"2013-08-19T17:08:29.67","username":"tiefling","apiKey":"ka73nd9s7n2ls9f3ka2n5p2k","requestSource":"website"}
这在询问来自 Chrome 的调用时......
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 19 Aug 2013 16:08:29 GMT
Content-Length: 213
{"id":"bba5e742d1af3de5921e8df0a1818530789c202a","dateCreated":"2013-07-22T17:57:20.143","lastLoggedIn":"2013-08-19T17:08:29.67","username":"tiefling","apiKey":"ka73nd9s7n2ls9f3ka2n5p2k","requestSource":"website"}
两者都显示 200,但在 Fiddler 中显示的图标略有不同 - Chrome 调用图标是一个红色圆圈,但除此之外,一切看起来都很笨拙。
欢迎提出任何想法,我现在遇到了一些困难。
补充:如果我单步执行代码,当我进行提取调用时,“sessionData”对象中的属性根本没有更新。该对象与执行 fetch 方法之前完全相同。
更新:自从我第一次写这篇文章以来,据我从 Fiddler 中看到的那样,代码现在已经完全停止进行调用。这在早些时候工作,但现在似乎无形地失败了,没有迹象表明可能是什么错误。调试 API 代码表明现在根本没有调用服务上的 GET 方法。
进一步更新:除了删除错误/成功回调之外,无需更改任何代码,这开始工作(有点)。如果我在 fetch 调用之后放置一个断点,那么它会完全正常工作(从我在 Fiddler 中看到的 - 我无法检查应用程序,因为成功回调是未连接的)。如果我删除断点,它现在会部分失败(Fiddler 中的红色圆圈,但响应为 200)。
这似乎是某种竞争条件?
我试过使用“完整”回调来获取信息以使用 textStatus,但它只是说“错误”——不是特别有用!
最佳答案
我终于找到了答案;这在上面的代码中并不明显。正在从这样的更高方法调用调用代码...
var authData = SiansPlanApp.session.getData(this.$loginUsername.val(), this.$loginPassword.val());
authData.save(authData.attributes, {
success: function() {
if (authData.generatedHash !== undefined && authData.generatedHash !== null && authData.generatedHash !== '')
MyApp.session.createSession(authData.generatedHash);
that.redirectToOrigin();
$.fancybox.close();
},
error: function (model, xhr) {
if (console !== undefined && console !== null) {
console.log('Login attempt failed: ' + xhr.responseText);
}
that.displayError('Username or password not recognised');
$.fancybox.close();
}
});
如您所见,createSession 方法后立即调用了 redirectToOrigin() - 虽然未显示,但足以说明该方法将页面重定向到根目录。失败的原因很简单 - 一旦通过重定向运行初始创建调用,就没有时间进行任何回调。
关于javascript - Backbone JS Model Fetch 在 Fiddler 中返回 200 但调用错误方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18318588/
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在编码时,我问了自己这个问题: 这样更快吗: if(false) return true; else return false; 比这个? if(false) return true; return
如何在逻辑条件下进行“返回”? 在这样的情况下这会很有用 checkConfig() || return false; var iNeedThis=doSomething() || return fa
这是我的正则表达式 demo 如问题所述: 如果第一个数字是 1 则返回 1 但如果是 145 则返回 145 但如果是 133 则返回 133 样本数据a: K'8134567 K'81345678
在代码高尔夫问答部分查看谜题和答案时,我遇到了 this solution返回 1 的最长和最晦涩的方法 引用答案, int foo(void) { return! 0; } int bar(
我想在下面返回 JSON。 { "name": "jackie" } postman 给我错误。说明 Unexpected 'n' 这里是 Spring Boot 的新手。 1日龄。有没有正确的方法来
只要“is”返回 True,“==”不应该返回 True 吗? In [101]: np.NAN is np.nan is np.NaN Out[101]: True In [102]: np.NAN
我需要获取所有在 6 号或 7 号房间或根本不在任何房间的学生的详细信息。如果他们在其他房间,简单地说,我不希望有那个记录。 我的架构是: students(roll_no, name,class,.
我有一个表单,我将它发送到 php 以通过 ajax 插入到 mysql 数据库中。一切顺利,php 返回 "true" 值,但在 ajax 中它显示 false 消息。 在这里你可以查看php代码:
我在 Kotlin 中遇到了一个非常奇怪的无法解释的值比较问题,以下代码打印 假 data class Foo ( val a: Byte ) fun main() { val NUM
请注意,这并非特定于 Protractor。问题在于 Angular 2 的内置 Testability service Protractor 碰巧使用。 Protractor 调用 Testabil
在调试窗口中,以下表达式均返回 1。 Application.WorksheetFunction.CountA(Cells(4 + (i - 1) * rows_per_record, 28) & "
我在本地使用 jsonplaceholder ( http://jsonplaceholder.typicode.com/)。我正在通过 extjs rest 代理测试我的 GET 和 POST 调用
这是 Postman 为成功调用我的页面而提供的(修改后的)代码段。 var client = new RestClient("http://sub.example.com/wp-json/wp/v2
这个问题在这里已经有了答案: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must
我想我对 C 命令行参数有点生疏。我查看了我的一些旧代码,但无论这个版本是什么,都会出现段错误。 运行方式是 ./foo -n num(其中 num 是用户在命令行中输入的数字) 但不知何故它不起作用
我已经编写了一个类来处理命名管道连接,如果我创建了一个实例,关闭它,然后尝试创建另一个实例,调用 CreateFile() 返回 INVALID_HANDLE_VALUE,并且 GetLastErro
即使 is_writable() 返回 true,我也无法写入文件。当然,该文件存在并且显然是可读的。这是代码: $file = "data"; echo file_get_contents($fil
下面代码中的变量 $response 为 NULL,尽管它应该是 SOAP 请求的值。 (潮汐列表)。当我调用 $client->__getLastResponse() 时,我从 SOAP 服务获得了
我一直在网上的不同论坛上搜索答案,但似乎没有与我的情况相符的... 我正在使用 Windows 7,VS2010。 我有一个使用定时器来调用任务栏刷新功能的应用程序。在该任务栏函数中包含对 LoadI
我是一名优秀的程序员,十分优秀!