This is the code that's called on a button click and works fine
var console = console ||
{log:function(msg){window.runtime.trace(msg);}};
console.log("opening link:"+bannerurl);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", bannerurl,false);
xmlhttp.send(null);
document.getElementById("banner").innerHTML=xmlhttp.responseText;
output is:
opening link:http://www.mysite.com
when I add the following line:
bannerurl=bannerurl+"?hi=22";
The output is:
> opening link:http://www.mysite.com?hi=22
> Error: NETWORK_ERR:XMLHttpRequest Exception 101
> setup1 at app:/js/result.js : 435
The url http://www.mysite.com?hi=22 (replaced real url with mysite as example) works perfectly fine and the code works fine in Firefox with forcecors but won't run in AIR.
rant about AIR
will answer this question later when I am allowed. The problem was that IE was set to work offline so only pages that were already cached worked but not the new ones (with different GET parameters)
I found out that Internet explorer was in offline mode. I almost never use IE so didn't notice this.
Related
I have a very simple function that downloads chunks of a file using an xhr request that looks like so:
var blobXHR = new XMLHttpRequest();
//api.media.chunkURL() returns the correct URL for each chunk
blobXHR.open("GET", api.media.chunkURL({
fileId: fileID,
chunkId: chunkNumber
}));
blobXHR.responseType = "arraybuffer";
blobXHR.onerror = function (e) {
console.log("Error: ", e);
};
var arrayBuffer;
blobXHR.onload = function (e) {
arrayBuffer = blobXHR.response;
};
blobXHR.send();
Now this download function works without any hitches at all using Chrome, Firefox, and just about every Android browser. Unfortunately, when using anything Safari or iOS based I get a very vague error in blobXHR.onerror(). When I output this error to the console I get this response under "e.currentTarget.responseText":
Error: InvalidStateError: DOM Exception 11
I've looked up many questions similar to this and nothing has seemed to work. Any reason why I would be experiencing this with only Safari/iOS browsers?
Edit: This is what I get when I console.log(blobXHR) within onerror():
This is likely a CORS issue. Make sure your server is properly configured to allow this:
http://enable-cors.org/server.html
Also be mindful that Safari won't allow localhost for CORS.
-------------------- UPDATE 2 ------------------------
I see now that what I am trying to accomplish is not possible with chrome. But I am still curios, why is the policy set stricter with chrome than for example Firefox? Or is it perhaps that firefox doesn't actually make the call either, but javascript-wise it deems the call failed instead of all together blocked?
---------------- UPDATE 1 ----------------------
The issue indeed seems to be regarding calling http from https-site, this error is produced in the chrome console:
Mixed Content: The page at 'https://login.mysite.com/mp/quickstore1' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost/biztv_local/video/video_check.php?video=253d01cb490c1cbaaa2b7dc031eaa9f5.mov&fullscreen=on'. This request has been blocked; the content must be served over HTTPS.
Then the question is why Firefox allows it, and whether there is a way to make chrome allow it. It has indeed worked fine until just a few months ago.
Original question:
I have some jQuery making an ajax call to http (site making the call is loaded over https).
Moreover, the call from my https site is to a script on the localhost on the clients machine, but the file starts with the
<?php header('Access-Control-Allow-Origin: *'); ?>
So that's fine. Peculiar setup you might say but the client is actually a mediaplayer.
It has always worked fine before, and still works fine in firefox, but since about two months back it isn't working in chrome.
Has there been a revision to policies in chrome regarding this type of call? Or is there an error in my code below that firefox manages to parse but chrome doesn't?
The error only occurs when the file is NOT present on the localhost (ie if a regular web user goes to this site with their own browser, naturally they won't have the file on their localhost, most won't even have a localhost) so one theory might be that since the file isn't there, the Access-Control-Allow-Origin: * is never encountered and therefore the call in its entirety is deemed insecure or not allowed by chrome, therefore it is never completed?
If so, is there an event handler I can attach to my jQuery.ajax method to catch that outcome instead? As of now, complete is never run if the file on localhost isn't there.
before : function( self ) {
var myself = this;
var data = self.slides[self.nextSlide-1].data;
var html = myself.getHtml(data);
$('#module_'+self.moduleId+'-slide_'+self.slideToCreate).html(html);
//This is the fullscreen-always version of the video template
var fullscreen = 'on';
//console.log('runnin beforeSlide method for a video template');
var videoCallStringBase = "http://localhost/biztv_local/video/video_check.php?"; //to call mediaplayers localhost
var videoContent='video='+data['filename_machine']+'&fullscreen='+fullscreen;
var videoCallString = videoCallStringBase + videoContent;
//TODO: works when file video_check.php is found, but if it isn't, it will wait for a video to play. It should skip then as well...
//UPDATE: Isn't this fixed already? Debug once env. is set up
console.log('checking for '+videoCallString);
jQuery.ajax({
url: videoCallString,
success: function(result) {
//...if it isn't, we can't playback the video so skip next slide
if (result != 1) {
console.log('found no video_check on localhost so skip slide '+self.nextSlide);
self.skip();
}
else {
//success, proceed as normal
self.beforeComplete();
}
},
complete: function(xhr, data) {
if (xhr.status != 200) {
//we could not find the check-video file on localhost so skip next slide
console.log('found no video_check on localhost so skip slide '+self.nextSlide);
self.skip();
}
else {
//success, proceed as normal
self.beforeComplete();
}
}, //above would cause a double-slide-skip, I think. Removed for now, that should be trapped by the fail clause anyways.
async: true
});
I wrote a little Chat using SSE for loading new messages.
It is working fine with Chrome, Safari and Opera while Firefox closes the connection after a few retries.
I'am using retry: 2000 (2s). Sometimes firefox is doing up to 10 events, sometimes only 1 or 2. I know from my serverstats, that more then 80% of my users are using firefox, so I need this working on firefox.
I'm using the latest version of firefox and I added a console.log() after every EventListener I'm using ('message', 'open', 'close').
Does anyone have an idea what to do?
Thanks a lot
think I solved the problem:
First I opend the EventSource in a function :
function chat_read() {
if(typeof(EventSource) !== "undefined") {
var source;
source = new EventSource('?link=chat_stream');
}
Now I tried to initialize the variable 'source' global (outside the function) and it is working now.
var source;
function chat_read() {
if(typeof(EventSource) !== "undefined") {
source = new EventSource('?link=chat_stream');
}
Beside this I wrote a function which is looking for the SSE 'open' event still firering and if it is not, it will restart the SSE.
I am using lwip tcp/ip stack with a STM32F4 to host a small configuration website for my device. I am refreshing a hidden iframe on my page to get updated SSI values and then using them in my tmp variable to update a graph. The code below works great in IE but in Firefox and Chrome tmp only gets a value once even though the temptemp element is getting updated values from my firmware.
var iframe = document.getElementById("iframeID");
var innerdoc = (iframe.contentWindow || iframe.contentDocument);
if(innerdoc.document)innerdoc = innerdoc.document;
(function worker() {
$.ajax({
url: 'data.shtml',
complete: function() {
document.getElementById("iframeID").contentWindow.location.reload();
setTimeout(worker, 1000);
tmp = innerdoc.getElementById("temptemp").value;
}
});
})();
"Domains, protocols and ports must match."
Have you checked the console for errors, when running this in Firefox and Chrome? I think you're being told that you cannot access unsafe JavaScript. Perhaps Internet Explorer is just fine with being insecure about how it runs JavaScript.
The following javascript function works fine for IE, Safari and Firefox. But it fails in Chrome(33.0.) and Opera (16.0.1196). Blank HTML page is displayed on loading.
function readTestXMLFile() {
if (window.ActiveXObject) {
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = 'false';
xmlDoc.load('test.xml');
}
else {
var requ = new XMLHttpRequest();
alert("a");
requ.open("GET", "test.xml", false);
alert("b");
requ.send(null); //This line is not working in chrome and opera
alert("c");
var xmlDoc = requ.responseXML;
alert(xmlDoc);
alert("d");
}
return xmlDoc;
}
Only 'a' and 'b' gets printed. It does not continue after that. Same result is observed if I use requ.send() or requ.send("") instead of requ.send(null).
If I remove the statement requ.send(null), then 'null' value is printed for xmlDoc. Still blank HTML loads.
Please let me know what is the right way to get this work on Chrome and Opera.
Thanks
SRB.
Your error message suggest that you are trying to access a local file which is treated as "Cross origin request" if you try and run local server it should work.
Take a look at this previously asked question with the same problem:
Cross origin requests are only supported for HTTP but it's not cross-domain
Then you would access http://localhost/.../test.xml instead of c:/localhost/.../test.xml
You can also set a flag for Chrome to allow local files to request local files: -allow-file-access-from-files
the call to the XMLHttpRequest.send method is Asynchronous so you need to modify the call a little bit. The modified code below will print the response content when the response is returned successfully:
requ.addEventListener("load", function(e) {
alert(req.responseText);
}, false)
requ.send(null);
Update:
I didn't notice that you made the send request call synchronous.
Edit
You need to launch chrome with this parameter to be able to access local files
--allow-file-access-from-files
ex: c:\Browser\chrome.exe --allow-file-access-from-files
I think that the problem is that you're passing null to the send() method. You are making a GET request, so you should call send without parameters. I think chrome throws an exception because of that. Just remove the null