開発サーバーのファイルにjavascript関数を書きました(すでにテスト済みで動作します)。問題なく動作します。ファイルを本番サーバーにアップロードし、テストすると次のエラーが発生します。
オペラトンボ 言います:
Uncaught exception: TypeError: Cannot convert 'App.system.ManageProductLines' to object
Firebug さんのコメント:
App.system.ManageProductLines is undefined
ファイルはまったく同じです (WinMerge で確認しましたが、違いは見つかりませんでした)。唯一の違いは、ファイルが置かれているサーバーです。
私の開発サーバーは Windows 上の Xampp の最新バージョンであり、運用サーバーは OpenSuse 上の Xampp の最新バージョンです。
誰が何が起こっているのか分かりませんか??
編集:
dtryon によって提案されたコード例を次に示します。
main.js で
App.system.ManageProductLines = function()
{
var init_row = function(row)
{
//function to add table row behavior
}
var reindex_odd_even_rows = function(table)
{
//function to reoder table when row is deleted
}
}
index.tpl (Smarty テンプレート):
{if $product_lines_url}
<script type="text/javascript">
App.system.ManageProductLines.init('manage_product_lines');
</script>
{/if}
最終的な HTML にはスクリプト タグが含まれているため、smarty テンプレートの if は実際に実行されていますが、開発サーバーでは関数が見つかりますが、運用サーバーでは見つかりません。
編集2:
Paul Butcher のおかげで、答えに近づいていると思います。次のことを試しました。
<script type="text/javascript">
$(document).ready(function()
{
App.system.ManageProductLines.init('manage_product_lines');
});
</script>
ただし、まだロードされないため、次のことを試しました。
<script type="text/javascript">
$(document).ready(function()
{
alert("Start document.ready");
if(App.system.ManageProductLines.init)
{
alert("Method found");
App.system.ManageProductLines.init('manage_product_lines');
}
else
{
alert("Method not found");
}
alert("End document.ready");
});
私が書いたことによると、次のアラートを受け取る必要があります。
"Start document.ready", "Method found" || "Method not found", "End document.ready"
奇妙なことに、「Start document.ready」しか表示されず、その後実行が停止したように見え、Opera Dragonfly と Firebug の両方で以前と同じエラーが表示されます。