I'm injecting a bit of code into my website (in other words the return value of http://localhost/FibReactHello/# ):
<div id="reactAppEntryPoint">
<script src="http://localhost/FibReactHello/scripts/bundle.js"></script>
</div>
This JS is run and converted to my react application as I would expected in both Chrome and IE11. In Firefox the JS is not executed. It just sits there like a bump on a log. The JS should have caused some HTML to be generated giving me arbitrary site content.
Here's the jQuery:
<div id="appEntrypt">
<button onclick="alertMe(event);">Inject React into Boost</button>
</div>
<script>
function alertMe(e) {//crappy named function
//e.preventDefault();
console.log('js works');
var url = "http://localhost/FibReactHello/#";
resetState();
$.ajax({
url: url, success: function (result) {
$("#appEntrypt").html(result);
write(result);
},
async: true
});
/*
$.get(url, function (data) {
$("#appEntrypt").html(data);
write(data);
});*/
return null;
}
function write(data) {
console.log(data);
};
function resetState() {
document.getElementById('appEntrypt').innerHTML = "";
};
</script>
I changed my Ajax call to dataType 'script' as opposed to 'html'. Also pointed directly to my bundle.js file. The script executes in Chrome and Firefox.
$.ajax({
url: devUrl,
success: function (result) {
console.log("successfully got script")
},
error: function (xhr, status, errorThrown) {
var output = "Error: " + errorThrown + ' status: ' + status + ' statusText: ' + xhr.statusText
console.log("failed to get script: " + output);
},
contentType: 'application/javascript',//IE
dataType: 'script',
cache: false,//required for IE
crossDomain: true,//required for IE
});
In IE this solved the issue of grabbing the script. But in my case my bundle.js needed a polyfill to learn IE how to run jabbascrept:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.