问题描述
任何人都可以详细说明可能出现的问题吗?关于在这一点上寻找什么,我没有真正的线索。
示例代码:
$。ajax({
url:uploader.fileupload('option','url'),
context:uploader,
success:function(response){
//登录上传者
console.log(上传者);
//记录这个 - >记录与登录上传者相同
console.log(this);
// loggin response - >清楚地显示一个上下文属性,其中包含此响应的正确数据
console.log(response);
// logging response.context - >显示undefined
console.log(response.context)
var done = uploader.fileupload('option','done');
done.call(this,null,response);
},
dataType:json
})
I我不习惯使用$ .ajax()调用中的context属性,我怀疑这个功能导致我的问题UE。
在ajax调用后的某段时间,代码片段会导致代码出现问题。我很确定这与ASYNC问题无关,因为问题已经存在于原始ajax请求的实际成功回调中。
我'已禁用已发送的php-headers,但它仍保持不变。我根据另一个主题尝试了这个,这意味着我的标题可能有问题。
我还在$ .ajax()中禁用了dataType attr,但后来我的响应被识别为json。
任何有关的帮助或提示如何调试非常感谢!
UPDATE:
删除ajax-call中的context属性确实解决了这个问题。
但是当console.logging()
我不确定这是否是您的问题,因为问题本身应该更好地指定。但是看看标题,似乎是 console.log()
是异步并通过引用传递的普通问题。
当您调用 console.log(object)
时,该对象将作为参考保留,不会立即打印。经过一段时间,当实际发生日志记录时,对象可能处于不同的状态(例如,在这种情况下,它可能具有属性)。
相反,当您记录 obj.property
时,调用是同步的,并且该属性尚未定义。
Can anyone elaborate on what might be going wrong? I have no real clue on what to look for at this point.
sample code:
$.ajax({
url: uploader.fileupload('option', 'url'),
context: uploader,
success: function(response){
//logging uploader
console.log(uploader);
//logging this --> logs the same as logging uploader
console.log(this);
//loggin response --> clearly shows a context attribute holding the correct data for this response
console.log(response);
//logging response.context --> shows undefined
console.log(response.context)
var done = uploader.fileupload('option','done');
done.call(this, null, response);
},
dataType:"json"
})
I'm not used to working with the context attribute in $.ajax() call and i'm suspecting this functionality to cause my issue.
The snippet causes issues in my code some time after the ajax call. I'm pretty sure this has nothing to do with ASYNC problems, since problem allready exists way back in the actual success-callback of the original ajax-request.
I've disabled php-headers which were sent, but it remains the same. I tried this based on another topic which implies something could be wrong with my headers.I've also disabled the dataType attr in $.ajax() but then my response isn't recognised as being json.
Any help or tips on how to debug are much appreciated!
UPDATE:removing the context attribute in the ajax-call does solve the issue.But why does it get appended to my response object (or at least seems to be appended) when console.logging()
I'm not sure if this is your problem because the question itself should be better specified. But looking at the title, it seems the plain old problem with console.log()
being asynchronous and passing by reference.
When you call console.log(object)
the object is kept as a reference and not printed immediately. After some time, when the logging actually happens, the object may be in a different state (for example as in this case, it may have an attribute).
On the contrary when you log obj.property
the call is synchronous and that property is not yet defined.
这篇关于javascript console.log(obj)显示现有属性'context',console.log(obj.context)显示undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!