Reputation: 1294
After I cleared chrome cookies&caches, I started getting XMLHttpRequest error when I click a link that its href is a javascript function. The link opens a bootstrap modal and they are created in a dojo ajax component dynamically. When I click the link, I get XMLHttpRequest
error.
jquery-1.11.3.min.js:5 XMLHttpRequest cannot load javascript:sa(5). Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
I import DOJO in the <header>
<script type="text/javascript"
src='<c:url value="/resources/js/dojo-release-1.10.0/dojo/dojo.js" />'
djConfig="parseOnLoad: true, usePlainJson: true, isDebug: false, async: false"></script>
and JQuery at the bottom of the <body>
<script type="text/javascript"
src='<c:url value="/resources/js/jquery-1.11.3.min.js" />'></script>
The dynamic link <a>
:
<a data-toggle="modal" data-target="#roomModal" href="javascript:sa(5)">Deluxe Double Room</a>
JS function is in another file.
function sa(accommodationRoomId) {
var modalHeader = document.getElementById("modalHeader");
modalHeader.innerHTML += accommodationRoomId;
}
This error started showing up after I cleared chrome caches and cookies. What should I do to fix this error?
PS: The project is running on Tomcat.
Upvotes: 0
Views: 562
Reputation: 1294
I changed my function as
function sa(_this) {
var modalBody = document.getElementById("modalBody");
modalBody.innerHTML += "<span>"+_this.id+"</span>";
console.log(_this);
}
and add onclick
for <a>
<a data-toggle="modal" id="5" data-target="#roomModal" onclick="sa(this)">Deluxe Double Room</a>
Upvotes: 2