views:

81

answers:

2
function publish(text) {
 $('#helpdiv').prepend(text);
}

function get_help(topic) {
  $.get(topic, publish);
}

<p>Hi. <a href="#" onclick="get_help('inline-help.html'); return false;">click here for more help.</a></p>
<div id="helpdiv"></div>

I've inherited this chunk of HTML and javascript above (snippet). It is/was going to be used as local help. Currently it is online only and it works fine. However, when I copy the files locally, I get "Permission Denied" in Internet Explorer and in Chrome doesn't do anything when I "click here for more help". What it's supposed to do is load the help content from inline-help.html and display it in the helpdiv div. Now here is the kicker, if I take the same files and copy them to inetpub on my PC and load them as http://localhost/hello.html it functions perfectly.

Presumably this is a security thing where the "local" zone isn't allowing me to load files off of the user's HD? But I'm not really sure what's going on and would like to understand this problem further and potentially come up with a workaround.

Any insight is greatly appreciated.

A: 

I don't think your browser is allowing you to run javascript locally (using the file:/// access method). But when you load it from http://localhost/ it works fine.

You need to either develop on a website, or use your localhost server.

webdestroya
That doesn't make a difference.
billb
@billb - ... You just said in your post that it works on `http://localhost/`, but fails when you load it locally thru the file
webdestroya
Misunderstood your comment. I thought you said to reference it through file:/// as opposed to c:\filename.html.Referencing it via http://localhost isn't an option because the end users will not have a web server installed.
billb
@Billb - Yes, but arent you putting this on a webserver?
webdestroya
No, it's going away from a web server and onto the end user's PCs. In a secured environment, they do not have internet access.
billb
+1  A: 

jquery's "get" uses xmlHttpRequest, which doesn't work on local files, unfortunately. If you really need to be able to fetch local data (or data from a different domain) asynchronously, you should use dynamic script tags. However that means the data file has to be reformatted as JSON data.

rob
Why doesn't it work? Is this intentional? Is there a workaround using another method or are dynamic script tags the only way to go?What's even more curious, if I use the WPF wrapped Chromium control, it works fine with local files. This makes me think it isn't jquery, but a browser setting.I am referring to this. http://chriscavanagh.wordpress.com/2009/08/25/a-real-wpf-webbrowser/
billb
It's not a jquery issue, but just the way it works. I agree it is dumb. Dynamic script tags are, to my knowledge, the only way that can work. You might be able to do something with Flash, but, you know....ick.
rob