ReferenceError:未定义jQuery jQuery.noConflict() [重复]
Posted
技术标签:
【中文标题】ReferenceError:未定义jQuery jQuery.noConflict() [重复]【英文标题】:ReferenceError: jQuery is not defined jQuery.noConflict() [duplicate] 【发布时间】:2016-10-27 12:12:51 【问题描述】:我就是无法理解这些错误:
" 阻止加载混合活动内容“http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
ReferenceError: jQuery is not definedjQuery.noConflict();
ReferenceError: jQuery 未定义 jQuery('#like_box').html(like_html);
"
有没有人遇到过这样的问题,所以我可以看看问题出在哪里并解决它。 这是我正在使用的代码:
jQuery.noConflict();
var good_image_url = "images/good.png";
var bad_image_url = "images/bad.png";
function load_stats(url)
jQuery.post("../../cgi-bin/test/like_new/wacko_like.pl",
URL : this.location.href,
func: 'get_stats'
, function(response)
setTimeout("finishAjaxLikeLoadStats('"+escape(response)+"')", 400);
);
function finishAjaxLikeLoadStats(response)
response = unescape(response);
var the_vals = response.split(":");
jQuery("#like_count").html(the_vals[0]);
jQuery("#dislike_count").html(the_vals[1]);
function generate_like_html()
var like_html = '<a href="javascript: void(0);" onclick="do_vote(document.location.href,1) "><img src="' + good_image_url +'" /></a>'
+ '<a href="javascript: void(0);" onclick="do_vote(document.location.href,2) "><img src="' + bad_image_url + '" /></a>'
+ '<span style="color: green">Likes: <span id="like_count">0</span></span>'
+ ' '
+ '<span style="color: red">Dislikes: <span id="dislike_count">0</span></span>';
jQuery('#like_box').html(like_html);
/* ok, now we have the stats - lets pre-update the numbers with real values :) */
load_stats(document.location.href);
function do_vote(LinkID,Type)
jQuery.post("../../cgi-bin/test/like_new/wacko_like.pl",
URL : this.location.href,
do_what: Type
, function(response)
setTimeout("finishAjaxLike('"+escape(response)+"')", 400);
);
function finishAjaxLike(response)
response = unescape(response);
var the_vals = response.split(":");
if (the_vals[0] == "1")
alert("Sorry, you can't vote (can't see your IP!)");
if (the_vals[0] == "2")
alert("Your vote has been counted, thanks!");
if (the_vals[0] == "3")
alert("Your vote has been updated accordingly");
jQuery("#like_count").html(the_vals[1]);
jQuery("#dislike_count").html(the_vals[2]);
这里是html:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="application/xhtml+xml; charset=utf-8" />
<meta http-equiv="Content-language" content="en-gb" />
<title>Like - Dislike</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="i_like.js"></script>
</head>
<body>
<p>Testing Like/Dislike Feature 1</p>
<div id="like_box"></div>
<script>
generate_like_html();
</script>
<!--
<a href="javascript: void(0);" onclick="do_vote(<%ID%>,1) "><img src="<%config.build_static_url%>/good.png" /></a>
<a href="javascript: void(0);" onclick="do_vote(<%ID%>,2) "><img src="<%config.build_static_url%>/bad.png" /></a>
<span style="color: green">Likes: <span id="like_count_<%ID%>"><%likes%></span></span>
<span style="color: red">Dislikes: <span id="dislike_count_<%ID%>"><%dislikes%></span></span>
-->
</body>
</html>
【问题讨论】:
【参考方案1】:这个错误很可能意味着您的网站正在通过 HTTPS 提供服务,但您正试图通过 HTTP 访问 jQuery 文件,而浏览器正在阻止这种情况发生。所以 jQuery 永远不会被加载。
解决方法:去掉jQuery URL开头的http:
:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
这将确保通过 http 或 https 检索 jQuery 文件,具体取决于您网站的访问方式。
【讨论】:
以上是关于ReferenceError:未定义jQuery jQuery.noConflict() [重复]的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript Uncaught ReferenceError: jQuery is not defined;未捕获的 ReferenceError:$ 未定义 [重复]
未捕获的 ReferenceError:未定义验证(jQuery 验证)
jQuery 错误 - 未捕获的 ReferenceError:$ 未定义 [重复]
DataTable 错误:未捕获的 ReferenceError:未定义 jQuery
Bootstrap 设置错误:未捕获 ReferenceError:未定义 jQuery 和未捕获错误:Bootstrap 的 JavaScript 需要 jQuery