首页 > Web开发 > 详细

Ajax.BeginForm 在 Chrome下的问题

时间:2014-01-14 19:21:59      阅读:706      评论:0      收藏:0      [点我收藏+]

项目背景:MVC4

代码:

bubuko.com,布布扣
 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  }
View Code

 

在用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

Ajax.BeginForm 在 Chrome下的问题

原文:http://www.cnblogs.com/guolf/p/3512135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!