$.ajax({url: path_to_file, cache: false, success: function(html_result){
$("#window_" + this.id + "_cont_buffer").html(html_result);})
那么现在。这个函数调用是在一个类的函数中。 this.id
是所述类的属性。这会将 this.id 的函数值传递给匿名函数的字符串,还是会在函数实际被调用时尝试对其求值,因此没有任何意义。
如果这不能按照我想要的方式工作,你能推荐我是如何实现的吗?
最佳答案
在 $.ajax()
的特殊情况下,可以使用 context
属性指定 this
。因此,Matthew 的解决方案为您提供了在函数中指定的 this
,您从中调用了 $.ajax
函数。
你可以看到 jQuery documentation有关为 success
回调设置 this
的更多信息。
关于javascript - JavaScript 回调函数中 `this` 的轻微混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2737817/