$.ajax({ // 左大括號之後必須空白 url: 'index.php', // 資料參數從這一列開始 async: false, type: "POST", dataType: 'json', data: { ... ... 'DATA': JSON.stringify(aData) }, success: function(obj_inf) { if(obj_inf.Code>0) { $('#form').submit(); } else { alert(obj_inf.ResponseStr); } } });
若緊接著寫會造成 smarty 編譯錯誤
// 這種寫法會造成 smarty 錯誤!! $.ajax({url: 'index.php', async: false, type: "POST", dataType: 'json', data: { ... ... 'DATA': JSON.stringify(aData) }, success: function(obj_inf) { if(obj_inf.Code>0) { $('#form').submit(); } else { alert(obj_inf.ResponseStr); } } });
錯誤訊息
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template mysmarty.tpl" on line xxx "$.ajax({url: 'index.php'," - Unexpected ": ", expected one of: "}" , " " ,