2013-10-21 58 views
0

我得到以下jquery錯誤:「Uncaught TypeError:屬性'setCurrency'的對象[object Object]不是函數」,我不能讓我的頭靠近。當你試圖改變貨幣的錯誤發生:http://aaronjpitts.com/temp/petiteannee未捕獲TypeError:對象[object對象]的屬性'setCurrency'不是函數

的setCurrency函數定義爲:

jQuery(document).ready(function ($) { 

    function setCurrency(id_currency) 
    { 
     $.ajax({ 
      type: 'POST', 
      headers: { "cache-control": "no-cache" }, 
      url: baseDir + 'index.php' + '?rand=' + new Date().getTime(), 
      data: 'controller=change-currency&id_currency='+ parseInt(id_currency), 
      success: function(msg) 
      { 
       location.reload(true); 
      } 
     }); 
    } 

}); 

我不得不換我的一些功能jQuery的noconflict功能把事情的工作 的jQuery (文件)。就緒(函數($)

我敢肯定,這事做與錯誤。任何人都可以看到正在生成該錯誤?該網站是建立在的Prestashop。

非常感謝

+0

我們需要查看您的代碼來診斷問題。 –

+0

哪裏定義了「setCurrency」函數? – Stphane

+0

我已更新我的原始帖子。感謝 –

回答

1

setCurrency聲明移到文檔之外準備就緒。

this示例所示,通過onclick參考找不到文檔就緒中聲明的函數。

$(document).ready(function() { 
    function test1(x) { 
     // I'm not working 
    } 

}); 

function test2(y) { 
    // I am working! 
    console.log(y); 

} 
+0

這將創建一個全局變量,污染全局命名空間,特別是如果你必須做很多次。您可以使用事件處理程序分配的功能按鈕避免這種情況:'$(「#例如按鈕)。在(」點擊」,函數(){setCurrency(‘the_currency_id’);});'文件:在[這裏] (http://devdocs.io/jquery/on)。 – iono

+0

當然,你的設計更好,但是OP在他使用onclick的地方提供了一個代碼。 – Saturnix

+0

對不起,我應該明確指出是針對OP的! – iono

相關問題