今天在項目中 用ajax跳轉並在url中傳數據時遇到了一個語法錯誤
function save(flag,checkFlag){ $('#allInfoForm').ajaxSubmit({ dataType : 'json', type : "post", data:{"operationFlag":flag,"checkFlag":checkFlag,"applicationId":'$!applicationId'}, success : function(data) { if (data.success) { Dialog.message(data.message,"提示", function() { self.location.href=contextPath+"/intopieces/applyintopiecewait/change.page?applicationId="+'$!applicationId'+"&customerId="+'$!customerId'+"&applyQuota="+'$!applyQuota'+"&serialNumber="+'$!serialNumber'; }); } else { Dialog.message(data.message); return false; } }, error : function(data) { Dialog.closeLoad(); Dialog.message("操作失敗"); return false; } }); }
SyntaxError: identifier starts immediately after numeric literal
參數的值為:
applicationId | 402881e74a384553014a385826a70003 |
applyQuota | 1000 |
customerId | 0000000049bb6a710149bb872c1d0007 |
serialNumber | 402881e74a384553014a385882e5000d |
解決辦法:
?applicationId="+'$!applicationId'+"&customerId="+'$!customerId'+"&applyQuota="+'$!applyQuota'+"&serialNumber="+'$!serialNumber';
拼接時 把要傳的數據用''括起來 即可。