admin管理员组

文章数量:1419583

Guys, I'm having a trouble with a cookie.

The error:

"linhaOS" isn't defined.

I wanna know if the cookie is null in the beggining of code.

$("#pApresentacao").click(function _click(){    



if ($.cookie("exibir") == null)
{   
    if ($("#hdLinhaOsView").val() != ""){i=$("#hdLinhaOsView").val()}
    else {i=0}; 
    $.cookie("exibir",1);
    $.cookie("linhaOS",i);
    _apresentacao(i);
}
else
{

    if ($.cookie("linhaOS") == null){i=0}
    else{i=$.cookie(linhaOS)};

    _apresentacao(i);
};

The first cookie(exibir) is working fine. But the second is not! How is it possible? It is almost the same.

Could someone help me?

Thks folks.

Guys, I'm having a trouble with a cookie.

The error:

"linhaOS" isn't defined.

I wanna know if the cookie is null in the beggining of code.

$("#pApresentacao").click(function _click(){    



if ($.cookie("exibir") == null)
{   
    if ($("#hdLinhaOsView").val() != ""){i=$("#hdLinhaOsView").val()}
    else {i=0}; 
    $.cookie("exibir",1);
    $.cookie("linhaOS",i);
    _apresentacao(i);
}
else
{

    if ($.cookie("linhaOS") == null){i=0}
    else{i=$.cookie(linhaOS)};

    _apresentacao(i);
};

The first cookie(exibir) is working fine. But the second is not! How is it possible? It is almost the same.

Could someone help me?

Thks folks.

Share Improve this question asked Jan 17, 2011 at 16:16 ThiagoThiago 1,5653 gold badges25 silver badges40 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Your problem isn't $.cookie(...) it's that the variable linhaOS is not defined.

else{i=$.cookie(linhaOS)};
                ^-------- If you use a variable you have to defined it
                          but this one doesn't appear anywhere in your code

So how to fix it? Well I suppose you wanted to use $.cookie("linhaOS") once again, and you just forgot to quote it as a string with "". So just quote it as a string, that will fix your problem.

It looks like you forgot to wrap linhaOS in string delimiters. Change

else{i=$.cookie(linhaOS)};

to

else{i=$.cookie("linhaOS")};

Looks like the statement that reads the cookie should be reading the string "linhaOS" and not the variable linhaOS.

本文标签: javascriptCookie problemcookie39s not definedStack Overflow