Yii2 jQuery在IE11中不起作用 [英] Yii2 jQuery not working in IE11
问题描述
我正在尝试创建一个页面,该页面在单击复选框时会更新表中的特定记录字段(理想情况下无需刷新页面).我以为jQuery/AJAX对我有用.
显然不是.
I'm trying to create a page that updates a specific records field in a table when a checkbox is clicked (ideally without refreshing the page). I thought jQuery/AJAX would work for me.
Apparently not.
我已经为此苦苦挣扎了一段时间,所以我决定将其缩小并真正简化它以找出不起作用的地方.表格的更新很好(从Chrome),没有刷新就没有. IE11都不起作用.
I've been struggling with this for a while, so I decided to scale it back and really simplify it to figure out what's not working. The updating of the table is fine (from Chrome), the not-refreshing isn't. And none of it works from IE11.
它目前托管在我的本地计算机上,所以我一部分想知道这是否与它有关,但是jQuery在以相同方式托管的其他站点上也能正常工作.
It's currently hosted on my local machine, so part of me is wondering if that's got something to do with it, however jQuery works fine on other sites I have hosted in the same way.
Yii2控制器操作:
public function actionTest() {
return 'This is just a static test';
}
(非常基本的)PHP页面: 这是页面渲染后的来源
The (very basic) php page: This is the source after the page has been rendered
<script src="/assets/ddb27309/jquery.js"></script>
<script src="/assets/eeb0e590/yii.js"></script>
<div id="loadToMe"> </div>
<script type="text/javascript">
$(document).ready( function() {
$('#loadToMe').load('/mycontroller/testing');
});
</script>
现在通常我希望当前空的div用字符串This is just a static test
填充-很简单.
Now normally I'd expect the currently empty div to be populated with the string This is just a static test
- nice and easy.
但是.
Chrome& FireFox::重定向到{mysite}/mycontroller/testing并显示给定的文本.
Chrome & FireFox: Redirect to {mysite}/mycontroller/testing and shows the given text.
IE 11:给我以下错误消息,但没有其他反应:
IE 11: gives me the following error message, but nothing else happens:
XMLHttpRequest: Network Error 0x2f76, Could not complete the operation due to error 00002f76.
当我使用$.get
,$.post
和$.ajax
(具有不同的语法差异)时,这两种浏览器的行为都相同,但有一个例外-IE11为POST提供了不同的错误消息.
This behaviour is identical for both browsers when I use $.get
, $.post
and $.ajax
(with their various syntax differences) with one exception - IE11 gives a different error message for a POST.
XMLHttpRequest: Network Error 0x800c0008, The download of the specified resource has failed.
我从各种来源尝试了各种方法,包括(但不限于-我不记得尝试过的所有方法)以下内容:
I've tried various things from various sources, including (but not limited to - I can't remember everything I've tried) the following:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" />
AddDefaultCharset utf-8
使用IE开发人员工具中的网络"标签,我分别将其用于POST和GET.
And using the network tab from IE developer tools I have this for a POST and a GET respectively.
Protocol Method Result Type Received Taken Initiator Wait Start Request Response Cache read Gap
HTTP POST 302 text/html 464 B 47 ms XMLHttpRequest 0 16 0 31 0 2902
HTTP (Aborted) text/html 506 B < 1 ms XMLHttpRequest 2902 0 0 0 0 47
链接的js文件是来自Yii2的文件(并且是$.load
在Chrome中运行所需的最低文件)-我丝毫没有碰过它们.
The linked js files are ones that came from Yii2 (and are the minimum required in order for the $.load
to work in Chrome) - I have not touched them in any way.
jQuery版本是v2.1.3
Yii2版本是v2.0.3
jQuery version is v2.1.3
Yii2 version is v2.0.3
推荐答案
因此,事实证明我有localeUrl,这就是问题所在!
So it turns out that I have localeUrls and that was the problem!
我的网址以当前的语言开头(即myurl.com/zh_CN/controller/action)
My urls are prepended with the current language (i.e. myurl.com/en/controller/action)
当我尝试加载/mycontroller/testing
时,它似乎已被UrlManager重定向到/en/mycontroller/testing
,因此重定向而不是加载(至少这是我从中了解的-我相对较新Yii2)
When I was trying to load /mycontroller/testing
it appears it was being redirected by the UrlManager to /en/mycontroller/testing
, hence the redirection and not loading (at least that's what I'm understanding from it - I'm relatively new to Yii2)
如果有人能指出我的立场,将对此做更详细的说明,我将不胜感激,但至少现在我可以继续进行我的项目了.
If anyone can point me to somewhere that will explain this in more detail I'd be grateful, but at least now I can crack on with my project.
谢谢
这篇关于Yii2 jQuery在IE11中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!