10
$('.upload').change(function () {
    var $container = $('#container');
    $container.find('input:checkbox, input:text, select').val('');

    var $thisUpload = $(this);
    var path = 'file:///' + $thisUpload.val().replace(/\\/g, "/");

    $.ajax({
        url: path,
        dataType: 'xml',
        success: function (data) {
        },
        error: function (request, status, error) {
            if (error.message == 'Permission denied') {
                //this is where i end up
            }
        }
    });
});

I know that a "blocked" file can cause this error in IE:

http://webactivedirectory.files.wordpress.com/2011/10/unblockfile.png

However, this file is not blocked. And it is located next to my .html file containing the code above.

What could possibly cause the "permission denied". I highly doubt this is due to the same origin policy.

Any help is MUCH appreciated. Thanks

Edit: This only occurs on my windows xp computer using ie7. Ie7-mode in win7 works well.

Edit #2: This only occurs for xml files which are downloaded as mail attachments.

Kev
  • 118,037
  • 53
  • 300
  • 385
Johan
  • 35,120
  • 54
  • 178
  • 293

6 Answers6

2

You say that this only occurs for xml files which are downloaded as mail attachments and only on win xp. Maybe some antivirus app or your e-mail client blocks xml attachments, do you download attachments via WWW client or some desktop client ?

el vis
  • 1,302
  • 2
  • 16
  • 32
  • I should add that the error occurs on some xmls downloaded from the web also. The problem is that i dont know whats different between the files that are workin and the files that arent. – Johan Aug 28 '12 at 12:31
2

It sounds like you are facing the same issue as this existing post jQuery AJAX problem in IE7 (possibly other versions as well) , in which it was solved by writing the code to make the ajax call without using jQuery (created XMLHttpObject, onreadystatechange, etc) and using jQuery to parse the XML.

Community
  • 1
  • 1
Brad Werth
  • 17,411
  • 10
  • 63
  • 88
1

You can't access local files like that through AJAX for obvious security reasons.

Note that the file:/// protocol points to the local file system of the client machine that is executing the code.

If the file is on your server, you should be able to revise your path so as to point to the server location.

David Hedlund
  • 128,221
  • 31
  • 203
  • 222
  • 1
    ACtually, I can. The problem only occurs on my xp machine. Sorry for not mentioning that – Johan Aug 09 '12 at 10:16
1

just remove file:/// and give the path itself. It means give path/filename.xml

paripurna
  • 135
  • 2
  • 10
  • Thanks but im afraid that i need file:/// for local xml files in ie. Otherwise it wont work – Johan Aug 31 '12 at 17:32
1

This is more a TIP then a answer, but it was to long for a comment.

Sorry, but on W7 IE7 (not IE9 browser mode) can't reproduce, on my XP virtual machine also I can't reproduce so what I can help you out is with some pointers.

You can debug jquery.ajax using the not minifyed version, I know that IE7 lacks in developer tools to debug, but you can install IE7 dev tools, it will work badly, but maybe it will work, if not, you will need to use eather alerts, or create your own console.log:

<div id="console" style="height:100px;position:fixed;bottom:0;left:0;rigth:0"></div>

function log(e){
    $('#console').prepend($('<div>').html(e))
}

You can start looking at function done( status, nativeStatusText, responses, headers ) in ajax: function( url, options )

What you need to look for is why the error ocures and if this is jQuery bug or a IE7 bug. Sorry I could not be more helpful.

cuzzea
  • 1,515
  • 11
  • 22
  • Thanks a lot. I actually know what error is beeing thrown though; its the "permission denied". My problem is that i cant figure out why it only occurs on certain files. – Johan Aug 31 '12 at 19:59
  • I don't think this is a problem, but did you checked the "allow data from other domains" setting in IE's Internet Options or other related settings? Also I know that in ie you might need to use XDomainRequest, not XMLHttpRequest for this kind of stuff, maybe jQuery did not implemented that(I don't think so)? – cuzzea Aug 31 '12 at 20:27
  • Good idea, i will try that as soon as i get to my xp machine. Ill keep you updated. Thanks – Johan Aug 31 '12 at 21:25
0

I highly doubt this is due to the same origin policy.

Are you sure? How are you accesing the page (url of the page) that does the ajax request? Keep in mind that if you point the browser to:

http://localhost.loc/page.that.does.the.ajax.request.html

and the ajax request will try to access the file:/// scheme, it will fail due to the same origin policy

Vlad Balmos
  • 3,372
  • 19
  • 34
  • I can place 2 xml files in the same folder, and get permission denied on 1 of them. The other one opens successfully. Do you still think that can be the issue? – Johan Sep 04 '12 at 11:25
  • it's my buest guess, try to load the webpage with the ajax code from the file system instead accessing by url and see what happens. like: `file:///htmls/page.with.ajax.response.html` – Vlad Balmos Sep 04 '12 at 11:32
  • Thanks for the tip, i will try it out as soon as i can – Johan Sep 04 '12 at 11:42