参考背景
A在此流可读的语法有点糊涂
现在的情况是我使用res.write在EX preSS写出来是正在慢慢流通过JSON.Stringify JSON对象。
The current situation is I am using res.write in express to write out the json object that is slowly being streamed by using JSON.Stringify.
app.get('/:foo', function (req, res) {
var connection = new sql.Connection(config, function(err) {
var request = new sql.Request(connection);
request.query(---SQL QUERY---);
res.header("Content-Type", "application/json; charset=utf-8");
res.header("Cache-Control", "max-age=3600");
res.write("[");
request.on('row', function (data) {
res.write(JSON.stringify(data)+",");
)};
request.on('done', function () {
res.write("]");
res.end();
});
这大约是我现在用的语法,
That is roughly the syntax I am using,
页眉都经过精细,
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Cache-Control: max-age=3600
Date: Fri, 22 Aug 2014 13:08:34 GMT
Connection: keep-alive
Transfer-Encoding: chunked
这个电话是用一个AJAX调用和双簧管电话完成。现在的问题是,即使这个JSON出现在我的网络状态200,我不能用它。双簧管发射失败,和AJAX发出失败也是如此。
This call was done with an AJAX call and an Oboe call. The problem is even though this JSON shows up in my network as status 200, I cannot use it at all. Oboe emits a fail, and AJAX emits a fail as well.
一个朋友说,这可能是是与DOM的时间,但不可能真正解释,他只是说,他知道有时他的开发者会包住呼叫在< DIV> 所以它呈现的DOM和住宿里面?我真的不明白他的意思。
A friend said it could be something to do with DOM timing but couldnt really explain it, he just said he knows sometimes his devs would encase the call in a <div>
so it renders inside the dom and stays? I dont really understand what he means.
我应该使用什么样的jQuery流?
Should I be using something like jQuery Stream?
previously当我有我的JSON的回调它加载罚款与Ajax调用,但写在流中的对象水库似乎导致它打破?
Previously when I had my JSON in a callback it was loading fine with the AJAX calls but writing the objects in a stream to res seems to cause it to break?
想通了,
我的JSON是添加一个尾随逗号。
my JSON was adding a trailing comma.
虽然浏览器不关心一个结尾逗号,将读取对象就好了,Ajax调用和Oboe.js呼叫只是失败,意外]
While the browser does not care about a trailing comma and will read the object just fine, AJAX Call and Oboe.js Call simply fails with unexpected ]