0

I have 2 files named index.html and mytext.txt in the same folder. I want to get contents of mytext.txt using an ajax call in the index.html. I use this code but it is only working in firefox not chrome:

$.ajax({
    url: "mytext.txt",
    dataType: 'text',
    success: function(data) {
        alert(data);
    }
});

I am opening index.html simply from explorer not server!

6
  • then why have you named the text file as folders.txt? Commented Mar 14, 2014 at 12:56
  • 1
    You need a webserver to do that. You can't run AJAX without it. Commented Mar 14, 2014 at 12:56
  • @putvande, why would OP need a webserver for that? Commented Mar 14, 2014 at 12:56
  • Using the file:// protocol is not allowed with ajax calls. It needs to be on a webserver, even if that webserver is http://localhost Commented Mar 14, 2014 at 12:58
  • @Amit Joki, sorry my mistake when typing here. Commented Mar 14, 2014 at 13:04

2 Answers 2

0

I think you'll have to start a webserver for this to work in chrome due to cross origin policy

Sign up to request clarification or add additional context in comments.

1 Comment

How would you say cross origin policy !
0

Refer

Link 1

Link2

var file = Components.classes["@mozilla.org/file/local;1"].
   createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.