Ajax.BeginForm 在 Chrome下的问题
项目背景:MVC4
代码:
1 @using (Ajax.BeginForm("Index", "GoingMeter", new AjaxOptions { OnSuccess = "result",OnBegin="begin" })) 2 { 3 // do something...... 4 } 5 ..... 6 7 function result(e) 8 { 9 //.... 10 } 11 12 function begin() 13 { 14 alert(‘提交了。。。‘); 15 }
在用Google Chrome、Safari时,result、beign 一直没执行,而在IE、Mozilla Firefox却正常。
最后在stackoverflow找到了答案:
I have found a weird solution to the problem. I was calling the ajax form‘s submit through an ‘a‘ tag like so:
<A href=‘#‘ onclick="javascript:$(‘#ajaxform‘).submit();">Remove</a>
For some reason calling the ‘.submit()‘ from an ‘a‘ tag was messing up in chrome causing a full page refresh instead of an ajax call. I fixed the issue by using the following code instead:
<input type=‘submit‘ value=‘Remove‘ />
This solution also worked when I needed to add javascript commands to the input to ask for confirmation before deleting. The only gripe is that I needed to swap around some markup to ensure that my buttons were happening within the form that they were submitting (something that I understand isn‘t always possible in all situations).
把<a href="#" onclick="$("form").submit();" class="easyui-linkbutton" data-options="plain:true,iconCls:‘icon-save‘" id="btnSave">保存</a>
改成 <input type="submit" value="保存"/>就一切OK了。
来自:http://guolingfa.cn/Article/Details/b342c20102874b75971126fa1bdb8a75
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。