【发布时间】:2015-03-19 17:05:13
【问题描述】:
我一直在使用下面的代码来创建一个 cookie,除了 INTERNET EXPLORER 之外的所有浏览器都可以正常工作。当我点击创建 cookie 按钮时,它会出现以下错误。
错误
Message: '$' is undefined
Line: 4
Char: 2
Code: 0
URI: http://localhost/js/scripts.js
代码
<p>Click on the <strong>Set Cookie</strong> button below to create the testing cookie.</p><br>
<button style="color: black" input type="button" onclick="set_cookie(<?php echo "'".$set_cookie_url."'" ?> );" <?php if(isset($_COOKIE["cookieid"])) { ?> Disabled <?php } ?>value='Set Cookie'><b>Set cookie</b></button>
JS 代码
function set_cookie(url){
$.get( url, { cookieid: "628929", projectid: "1" }, set_cookie_complete);
$('body').modal('show') ;
}
function set_cookie_complete(){
location.reload();
}
function unset_cookie(url){
$.get( url, { cookieid: "628929", projectid: "1" }, unset_cookie_complete);
$('body').modal('show') ;
}
function unset_cookie_complete(){
location.reload();
}
谁能帮我摆脱这个错误并设置 cookie
【问题讨论】:
-
请注意:在 echo 命令中使用单引号 ( '\'' ) 表示字符串和逗号 ( , ),这将使您的 PHP 代码运行得更快 ;)
-
好的,但是你说的和上面的问题没有关系吧?
-
是的,很可能。您的问题出在 JS 中,而不是 PHP 中。 jQuery 库是否正确加载?
-
我对 jquery 很陌生,我只使用这个链接来加载库
-
你用什么IE? jQuery 2.x 不支持旧版本!尝试 IE10 或 IE11(如果可能)。如果没有,你必须使用jquery 1.11.x
标签: javascript php jquery internet-explorer cookies