The Problem
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.
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.
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.
The Yii2 controller action:
public function actionTest() {
return 'This is just a static test';
}
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>
Now normally I'd expect the currently empty div to be populated with the string This is just a static test
- nice and easy.
However.
Chrome & FireFox: Redirect to {mysite}/mycontroller/testing and shows the given text.
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.
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
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
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 version is v2.1.3
Yii2 version is v2.0.3