I have been using the below code, to create a cookie, this works completely fine in all the browsers except INTERNET EXPLORER .. it gives the below error when i click on create cookie button.
Error
Message: '$' is undefined
Line: 4
Char: 2
Code: 0
URI: http://localhost/js/scripts.js
Code
<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 Code
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();
}
can anybody help me to get rid of this error and set the cookie
For IE8 and older you cannot use jQuery 2.x
Change your link to version 1.11.x. For such simple code you use there should be no differences.
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
Note: using '//' on the start of the URL helps browser to decide how to process it and allow to use both HTTP or HTTPS. Not using it may result in url " http://your.server.com/ajax.googleapis.com/ajax/ ..."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.