最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cookie problem - cookie's not defined - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论