javascript是經(jīng)典的敏感性語言,小小問題都會導(dǎo)致整體功能出錯。
自己調(diào)用document.form[0].submit()的時候,會出現(xiàn)submit is not a function錯誤(使用firefox的firebug調(diào)試,非常好用),原因是頁面的form中出現(xiàn)具有name=submit的元素,這樣會影響到j(luò)avascript調(diào)用submit()函數(shù),改掉那個name=submit的元素即可。
另外submit提交struts1.2的action時候,如果后面跟有?method=***等的參數(shù),那么注意,這個函數(shù)里面不要出現(xiàn)有method等關(guān)鍵字。
例如函數(shù):
function changeAction(methodArg, wayArg){
with (document.forms[0]) {
action="<html:rewrite page='/BgdInfoReportAction.do'/>?method="+ methodArg + "&way=" + wayArg;
submit();
}
}
使用?method=***是在使用dispatchAction時候的做法原來我的參數(shù)名稱是method和way,
結(jié)果報錯:Action[/BgdInfoReportAction] does not contain method named post
原因是?后的method變得沒有效,那么這個submit提交使用默認(rèn)的post方法提交(servlet默認(rèn)分為post和get方法嘛),
后來我將method改成methodArg和way改成wayArg,這個action就能夠正確執(zhí)行。
我重復(fù)測試改與不改的效果,仍然與上面一樣。總結(jié)原因可能是是javascript的一些關(guān)鍵字沖突,所以盡量使用特殊一點(diǎn)的字符串作為變量名。
自己調(diào)用document.form[0].submit()的時候,會出現(xiàn)submit is not a function錯誤(使用firefox的firebug調(diào)試,非常好用),原因是頁面的form中出現(xiàn)具有name=submit的元素,這樣會影響到j(luò)avascript調(diào)用submit()函數(shù),改掉那個name=submit的元素即可。
另外submit提交struts1.2的action時候,如果后面跟有?method=***等的參數(shù),那么注意,這個函數(shù)里面不要出現(xiàn)有method等關(guān)鍵字。
例如函數(shù):
function changeAction(methodArg, wayArg){
with (document.forms[0]) {
action="<html:rewrite page='/BgdInfoReportAction.do'/>?method="+ methodArg + "&way=" + wayArg;
submit();
}
}
使用?method=***是在使用dispatchAction時候的做法原來我的參數(shù)名稱是method和way,
結(jié)果報錯:Action[/BgdInfoReportAction] does not contain method named post
原因是?后的method變得沒有效,那么這個submit提交使用默認(rèn)的post方法提交(servlet默認(rèn)分為post和get方法嘛),
后來我將method改成methodArg和way改成wayArg,這個action就能夠正確執(zhí)行。
我重復(fù)測試改與不改的效果,仍然與上面一樣。總結(jié)原因可能是是javascript的一些關(guān)鍵字沖突,所以盡量使用特殊一點(diǎn)的字符串作為變量名。