PDA

View Full Version : ajax request for local file works in FF but not in Chrome.



scaddenp
8 Apr 2010, 5:13 PM
Using ext 3.1.1, with ext-basex as well in an application hosted entire on a USB stick.
Loading an image into OpenLayers, I want to read an associated image descriptor file living in same directory as my top html file.

Code looks like:

function readFile(filename) {
Ext.Ajax.request({
url: filename,
success: parseFile,
failure: parseError,
async:false
});
}

function parseFile(response) {
var lines = response.responseText.split("\r\n");
var xleft = parseFloat(lines[4]) + parseFloat(lines[0]);
var xright = parseFloat(lines[4]) + img.width * parseFloat(lines[0]);
var ytop = parseFloat(lines[5]) + parseFloat(lines[3]);
var ybot = parseFloat(lines[5]) + img.height * parseFloat(lines[3]);
bounds = new OpenLayers.Bounds(xleft,ybot,xright,ytop);
}

function parseError(response) {
alert('fail:' + response.responseText);
}

function addImageLayer(filename,title){
img.src = filename;
var pos = filename.lastIndexOf('.');
if (pos != -1) {
readFile(filename.substring(0,pos+2) + filename.charAt(filename.length-1) + 'w');
}
....
so the filename passed into readFile is just "myimage.pgw" and lives in same directory as the code above.
FF works fine, reads the file as a response which parseFile handles. However Chrome just
fails with 404. Chrome is usually easier to deal with for local files than FF. Anyone got any ideas???

hendricd
8 Apr 2010, 5:40 PM
@scaddenp--

Chrome version, platform?

scaddenp
11 Apr 2010, 1:47 PM
Chrome version is 5.0.342.9 beta
Platform windows.

In the ext-basex-debug code, the difference between FF and Chrome occurs at line 1041
r.send(postData || null);

In Chrome, this fires an exception, taking you into the catch block.
The exception object exr, looks like:


exr: XMLHttpRequestException

code: 101
constructor: function XMLHttpRequestException()
message: NETWORK_ERR: XMLHttpRequest Exception 101
name: NETWORK_ERR
__proto__: Object



Thanks very much for your interest.

hendricd
12 Apr 2010, 1:46 PM
Chrome version is 5.0.342.9 beta
Platform windows.

In the ext-basex-debug code, the difference between FF and Chrome occurs at line 1041
r.send(postData || null);

In Chrome, this fires an exception, taking you into the catch block.
The exception object exr, looks like:



exr: XMLHttpRequestException

code: 101
constructor: function XMLHttpRequestException()
message: NETWORK_ERR: XMLHttpRequest Exception 101
name: NETWORK_ERR
__proto__: Object





Thanks very much for your interest.


@scaddenp--
Since that release is a BETA, its likely Chrome is planning some changes with regards to same-origin policies etc. Have you noticed any new user-controlled settings available on an Options menu somewhere?

The problem may also disappear in a later release. To soon to react heavily just yet..

nilclass
27 May 2010, 12:38 PM
see here: http://code.google.com/p/chromium/issues/detail?id=40787
and here: http://code.google.com/p/chromium/issues/detail?id=30834

scaddenp
27 May 2010, 2:25 PM
Well actually, Chrome have said, this is design and will not fix. See http://code.google.com/p/chromium/issues/detail?id=40787