2013-07-09 22 views
2

我有一個wordpress網站與Woocommerce和WPML插件運行多語言。 在結帳頁面上,我有一個javascript錯誤(我對js不太好)。對象函數沒有方法(我不是一個JavaScript編碼器)

錯誤是:

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

這裏什麼叫錯誤:

jQuery(document).ready(function(){ 
if(jQuery.cookie != undefined) { 
    // Check if cookie are enabled 
    jQuery.cookie('wpml_browser_redirect_test', '1'); 
    var cookie_enabled = jQuery.cookie('wpml_browser_redirect_test') == 1; 
    jQuery.removeCookie('wpml_browser_redirect_test'); 
    ... 

這裏是一個與函數的文件:

(function ($, document, undefined) { 

var pluses = /\+/g; 

function raw(s) { 
    return s; 
} 

function decoded(s) { 
    return decodeURIComponent(s.replace(pluses, ' ')); 
} 

$.cookie = function (key, value, options) { 

    // key and at least value given, set cookie... 
    if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) { 
     options = $.extend({}, $.cookie.defaults, options); 

     if (value === null) { 
      options.expires = -1; 
     } 

     if (typeof options.expires === 'number') { 
      var days = options.expires, t = options.expires = new Date(); 
      t.setDate(t.getDate() + days); 
     } 

     value = String(value); 

     return (document.cookie = [ 
      encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), 
      options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE 
      options.path ? '; path=' + options.path : '', 
      options.domain ? '; domain=' + options.domain : '', 
      options.secure ? '; secure' : '' 
     ].join('')); 
    } 

    // key and possibly options given, get cookie... 
    options = value || $.cookie.defaults || {}; 
    var decode = options.raw ? raw : decoded; 
    var cookies = document.cookie.split('; '); 
    for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { 
     if (decode(parts.shift()) === key) { 
      return decode(parts.join('=')); 
     } 
    } 

    return null; 
}; 

$.cookie.defaults = {}; 

$.removeCookie = function (key, options) { 
    if ($.cookie(key, options) !== null) { 
     $.cookie(key, null, options); 
     return true; 
    } 
    return false; 
}; 

})(jQuery, document); 

由於我不知道的JavaScript,我真的不知道該怎麼想。我知道「對象函數沒有方法」是一個常見的問題,我查看了其他帖子,但我無法想象它。

所以大家(和女孩),我需要幫助這一個。

感謝

布魯諾

回答

0

,如果你不包含任何插件jQuery.cookie這會發生。

+0

嗨,非常感謝回答。這是我檢查的第一件事,它包含在中。沒有404或類似的問題,沒關係。我檢查了螢火蟲和鍍鉻控制檯。 –

+0

@BrunoHug:它包含在jQuery之後嗎?還有其他的jQuerys嗎? – SLaks

+0

它是在jquery(jQuery v1.8.3)之後。 是的,你是對的,還有另一個由主題加載(jQuery v1.7.1)。這可能是問題嗎? –

0

我同意上面的帖子,但是這也應該有幫助: 你的錯誤意味着當你調用/使用.removeCookie函數時,你的代碼無法找到/找到一個以該名稱執行的函數/方法。 確保帶.removeCookie方法的文件與代碼文件位於同一文件夾中,並確保文件使用.removeCookie方法'包括'該文件。在'.removeCookie'之前,你可能還需要寫點別的東西,希望這可以帶來一個解決方案。 此外,如果您將所有代碼用於Wordpress,您可能需要獲得有關Wordpress的幫助。也許這是不正確的安裝或使代碼故障的東西...

+0

,非常感謝您的回答。這是我檢查的第一件事,它包含在中。沒有404或類似的問題,沒關係。我檢查了螢火蟲和鍍鉻控制檯。 Wordpress安裝得很好(我重新安裝了它)。 –

相關問題