我正在维护一个动态插入一些对话框的应用程序。这些对话框通常包含在对话框出现时加载的 javascript,例如:
<script type="text/javascript" src="/js/charCount.js"></script>
<script>
$(function() {
$('#container').charCount(function() {
/* more code here */
});
});
父页面已经加载了 jquery,但是对话框添加了一个新的 javascript,它是 charCount,它为 jQuery 添加了一个新方法。这工作正常,但是,当我们移动到 CDN 时,charCount.js
现在从那里加载,我得到Incaught TypeError: Object [object Object] has no method 'charCount'
如果我在本地加载 javascript,它工作正常,没有任何问题。
我看到的唯一区别是如何请求 javascript。当它在本地加载时,请求标头如下所示:
Accept:text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Cookie:__utma=201217592.1524881892.1360801695.1367952052.1367956136.78; __utmb=201217592.2.9.1367956140967; __utmc=201217592; __utmz=201217592.1366916286.66.12.ut$
Host:localhost
Pragma:no-cache
Referer:localhost
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
X-Requested-With:XMLHttpRequest
从 CDN 加载时,请求标头如下所示:
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Cookie:__utma=201217592.1524881892.1360801695.1367952052.1367956136.78; __utmb=201217592.2.9.1367956140967; __utmc=201217592; __utmz=201217592.1366916286.66.12.
Host:<cdnurlhere>
Pragma:no-cache
Referer:localhost
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31