admin管理员组

文章数量:1296873

I am using the jQuery cookie plugin (also tried with EZCookie), I am stuck with this error in firefox:

'$.cookie is not a function'
 at line:
if(!( $.cookie('name') == null) ) { 

I get a different javascript error in IE 6

"Object doesn't support this property or method"

Strange thing is when I mented $(document).ready(function() { ,

I don't get any error, but then I also don't see the cookie (even after setting the cookie from another application).

Anybody has a clue whats going on here....

Here is the code am using:

<script type="text/javascript">
var var2= "";
$(document).ready(function() {
        if($.cookie('name').length > 0) { 
            alert("cookie present"+$.cookie('name'));
            <% 
                String[] var1= (String[]) ponentRequest.getComponentSession().getValue("var"); 
                if(!(null == offices)){
                for(int i = 0; i < var1.length; i++){%>

                var2+=<%=var1[i]%>+",";     

                <%}
                }%> 

            $('#tempCookieVal').val(var2+$.cookie('name')); 
            $('#cookieForm').submit();  
        }else{
            alert("no cookie");
            $('#tempCookieVal').val("NoCookie");
            $('#cookieForm').submit();    
        }
        alert("cookie check done");

});
    </script>
<form id="cookieForm" >
<input name="tempCookie" type="hidden" id="tempCookieVal" />
</form>

I am using the jQuery cookie plugin (also tried with EZCookie), I am stuck with this error in firefox:

'$.cookie is not a function'
 at line:
if(!( $.cookie('name') == null) ) { 

I get a different javascript error in IE 6

"Object doesn't support this property or method"

Strange thing is when I mented $(document).ready(function() { ,

I don't get any error, but then I also don't see the cookie (even after setting the cookie from another application).

Anybody has a clue whats going on here....

Here is the code am using:

<script type="text/javascript">
var var2= "";
$(document).ready(function() {
        if($.cookie('name').length > 0) { 
            alert("cookie present"+$.cookie('name'));
            <% 
                String[] var1= (String[]) ponentRequest.getComponentSession().getValue("var"); 
                if(!(null == offices)){
                for(int i = 0; i < var1.length; i++){%>

                var2+=<%=var1[i]%>+",";     

                <%}
                }%> 

            $('#tempCookieVal').val(var2+$.cookie('name')); 
            $('#cookieForm').submit();  
        }else{
            alert("no cookie");
            $('#tempCookieVal').val("NoCookie");
            $('#cookieForm').submit();    
        }
        alert("cookie check done");

});
    </script>
<form id="cookieForm" >
<input name="tempCookie" type="hidden" id="tempCookieVal" />
</form>
Share Improve this question edited Mar 8, 2011 at 20:22 jqueryEnthusiast asked Mar 8, 2011 at 19:47 jqueryEnthusiastjqueryEnthusiast 1551 gold badge7 silver badges17 bronze badges 4
  • See answer by Mikhail and if that doesn't help, see if you can reproduce somewhere that we can see it ( jsfiddle would be great) – JAAulde Commented Mar 8, 2011 at 19:53
  • I updated with code, I am using only once include of jquery.js. – jqueryEnthusiast Commented Mar 8, 2011 at 20:23
  • Then what you've posted so far is not enough. We really need to see all this in context, running live even. – JAAulde Commented Mar 8, 2011 at 22:43
  • You can post a link to your website - we'll view the source ;) – Mikhail Commented Mar 9, 2011 at 15:13
Add a ment  | 

2 Answers 2

Reset to default 9

Check to make sure you don't include jquery.js twice. Including it the second time will destroy whatever addons you have added.

Same goes for including any javascript that overwrites $

Example:

<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/js/jquery.js"></script>

This will act as if you've never included cookie

Did you include the cookie plugin ? If yes, is it after the jquery.js include ?

本文标签: javascriptquotcookie is not a functionquot error in FF eventhough I include itStack Overflow