2012-06-06 13 views
11

se si cerca di ottenere il valore di cookie se è impostato e aggiorna un div con cookie valore, altrimenti generare un numero casuale compreso tra 80 e 100, impostarlo come cookie e quindi aggiornare div.Funzione oggetto (a, b) {return new e.fn.init (a, b, h)} non ha alcun metodo 'cookie'

im ottenere l'errore:

Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie' 

heres il mio codice:

$(document).ready(function(){ 

    var thecounter = ''; 

    if ($.cookie('thecounter') == null) 
    { 
     thecounter = $.randomBetween(80, 100); 
     $.cookie('thecounter', thecounter, { path: '/' }); 
    } 
    else 
    { 
     thecounter = $.cookie('thecounter'); 
    } 

    $('dd-counter-num').html(thecounter); 

    setTimeout(newtime, 5000); 

}); 

function newtime() { 

    var newtime = $.cookie('thecounter') + $.randomBetween(1, 2); 
    $.cookie('thecounter', newtime, { path: '/' }); 
    $('dd-counter-num').html(newtime); 
    setTimeout(newtime, 5000); 

} 
+0

Sembra che questo era il plugin che stavate cercando: https://github.com/carhartl/jquery-cookie Ho pensato di aggiungo dal momento che questo mi ha aiutato pure. –

risposta

14

Non c'è metodo nella cookieseriejQuery.

Forse il codice richiede su jquery-cookie o un altro plug-in?

Felice codifica.

+1

ho pensato che il metodo fosse incorporato in jquery da un tutorial che ho letto che non includeva l'URL del plugin. ho trovato il plugin e ora funziona. grazie. – scarhand

+0

ciao scarhand ... da dove hai preso il plugin jquery-cookie? – antnewbee

+0

ecco il plugin: http://plugins.jquery.com/cookie/ – ezawadzki

2

Assicurarsi di fare riferimento a jquery.cookie.js dopo eventuali riferimenti jquery standard.

I encountered this error when editing a page using Foundation . It was first loading jquery, then jquery.cookie.js, then the foundation.min.js file. I didn't realize was the custom foundation.min.js file already had jquery built-in, so executing JQuery again was causing the cookie javascript to fail.

Problemi correlati