我遇到一个问题,即使代理已成功加载,jQuery 函数也没有被调用(据我所知)。我们进行的调用在第一次加载时工作正常,但是当我们尝试通过 AJAX 加载此脚本时,它调用所需的 $.proxy() 到 Initialise 函数,但实际上并没有调用该函数。
代码中加载的动态是:
<script language="JavaScript"><!--
var ctrl = new VideoControl({"Id":"bc1093c8290a4037846c2052695a7d3a"}, "...");
//-->
</script>
创建对象的 javascript 是:
function VideoControl(controlIds, videoMarkUp) {
this.controlIds = controlIds;
this.videoMarkUp = videoMarkUp;
var thisControl = this;
$(function () { $.proxy(thisControl.Initialise(), thisControl); });
}
VideoControl.prototype.Initialise = function () {
// do stuff
}
所以调用了 main 函数,但是当它通过 Chrome 或 IE 中的 AJAX 控件加载时,不会调用 Initialise() ......但这在 firefox 中确实有效。
有一个stackoverflow answe r 这解释了为什么 $function 没有被调用,但是我如何让它达到它会调用的程度(类似于 firefox 处理它的方式)
有人知道 firefox 在使用 jQuery 时与其他浏览器有什么不同吗?
chrome 开发者工具上没有显示任何错误,是否还有其他地方可以查看以诊断此问题?
提前谢谢你。
最佳答案
So the main function is called, but the Initialise() is not called when this is loaded in via AJAX
$(function() {})
是 .ready()
的别名; .ready()
的处理程序最多应调用一次。 AJAX 出现在文档加载后? , 其中.ready()
之前曾调用,$.isReady
设置为 true
防止随后的处理程序 .ready()
或 $(function(){})
从被调用。
尝试删除 $(function() {})
包裹着
function VideoControl(controlIds, videoMarkUp) {
this.controlIds = controlIds;
this.videoMarkUp = videoMarkUp;
var thisControl = this;
$.proxy(thisControl.Initialise, thisControl);
}
使用
$(document).ready(VideoControl)
虽然,不确定为什么$.proxy
在这里使用? , 作为 context
的 thisControl.Initialise
似乎没有更改为不同的 context
: this
?
另请注意 js
在问题 thisControl.Initialise()
调用函数;应引用函数的位置 jQuery.proxy( function, context [, additionalArguments ] )
关于javascript - jQuery.proxy() 函数未在 Chrome 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34617238/