且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么jQuery的Ajax自动运行脚本?

更新时间:2023-12-05 08:17:28

当有人回答得更早(答案被删除?)时,jQuery ajax会根据您请求的内容类型自动选择要执行的操作.(不幸的是,文档不足的功能).加载外部js不仅会在浏览器获取脚本后返回,还会运行脚本.

As someone answered earlier (whose answer got deleted?), jQuery ajax automatically chooses what to do depending on what type of content you requested. (An unfortunately under-documented feature). loading an external js will not just return when the browser has fetched the script, it will also run the script.

每当以后再包含jQuery时,它都会重写window.jQuery对象,因此删除了jQuery.prototype.dialog等.

Whenever you re-include jQuery at a later point, it rewrites the window.jQuery object, therefore removing the jQuery.prototype.dialog, etc.

在这种情况下,Firefox .watch函数可能会很有用,以查看在何处重新定义了某些内容.例如,这将为您提供所有重新定义jQuery的堆栈跟踪:

The Firefox .watch function can be helpful in cases like this, to see where something got redefined. This, for example, would give you a stack trace of anything that redefines jQuery:

window.watch('jQuery',function() { console.trace() } )