Why doesn't Ajax.BeginForm work in Chrome?

ⅰ亾dé卋堺 提交于 2019-12-03 10:42:59

There's an issue with Microsoft AJAX and certain webkit browsers. I ran into this issue myself a while ago, and the fix is pretty simple. Create a webkit.js file and put this in the contents:

Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if( navigator.userAgent.indexOf( 'WebKit/' ) > -1 )
{
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat( navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}

Then either within your ScriptManager or somewhere in your page (preferably in a master page, I added it near the end), add the script reference:

<Scripts>
    <asp:ScriptReference Path="webkit.js" />
</Scripts>
//OR
<script src="webkit.js">

Can't remember the original site that I found the info, but this I was able to get from this page. Good luck!

you may update your project to use asp.net MVC 3 , within mvc 3 , jquery ajax is the default

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!