为什么没有在Chrome Ajax.BeginForm工作? [英] Why doesn't Ajax.BeginForm work in Chrome?

查看:113
本文介绍了为什么没有在Chrome Ajax.BeginForm工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C#.NET MVC2工作,我试图创建一个调用该删除数据库记录(RemoveRelation)方法的Ajax表单。删除的记录的过程是工作如预期。
记录被删除后的形式应该调用javascript函数,可以消除视觉效果的记录(RemoveRelation(10))。这是通过一个AJAX进行调用在Internet Explorer 9和Firefox 4都担任但是打算在Chrome出于某种原因,更新是不会发生throuhg AJAX调用和整个页面被刷新,当窗体删除记录正在被提交(这是不正确的,据说是正与AJAX功能所产生的形式)。这是code与我产生的形式:

I'm working with c#.NET MVC2 and I'm trying to create an ajax form that calls a method that deletes a database record (RemoveRelation). The process of deleting the record is working as intended. After the record is deleted the form should call a javascript function that removes the record from the visuals (RemoveRelation(10)). This is done through an AJAX call that on Internet Explorer 9 and Firefox 4 are all working as intended however on Chrome for some reason the update is not happening throuhg an AJAX call and the whole page is refreshing when the form to delete the record is being submitted (this is incorrect as the form is supposedly being generated with AJAX functionality). This is the code with which I am generating the form:

 <% using (Ajax.BeginForm("RemoveRelation", "Relations",
       new AjaxOptions { OnSuccess = "function() { RemoveRelation(10); } ", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Relation10" },
       new { id = "DeleteForm10" }))
   { %>

此外在Chrome我有一个单独的Ajax.BeginForm另一个问题。

Additionally on Chrome I have another issue with a separate Ajax.BeginForm.

<% using (Ajax.BeginForm("AddRelation", "Relations", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "AddRelation" }, new { id = "AddRelationForm" }))
  { %>

上面的表格开始code用于关系添加到列表中,而不是删除它们。我再次强调,在IE9和FF4上述工作为目的,对铬,而不是增加一个,并通过AJAX更新,它代替将记录两次,并再次刷新整个页面,而不是做了ajax的更新。

The above Begin Form code is used to add Relations to the list instead of the removing them. Once again I stress, on IE9 and FF4 the above is working as intended, on chrome instead of adding one and updating through ajax, it's instead adding the record twice and once again refreshing the whole page rather than doing the ajax update.

这是为什么打破铬?

推荐答案

我发现一个奇怪的解决问题的办法。我打电话了ajax形式的通过的一个标签提交像这样:

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>

由于某些原因调用从'.submit()'的'一'标记在镀铬搞乱造成整页刷新,而不是一个Ajax调用。我通过以下code,而不是固定的问题:

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' />

当我需要添加JavaScript命令到输入在删除前要求确认

该解决方案还工作。唯一的抱怨是,我需要周围的一些标记交换,以确保我的按钮是在表单中发生的,他们提交(的东西,我的理解并不总是能够在所有情况下)。

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).

这篇关于为什么没有在Chrome Ajax.BeginForm工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆