0

I have a text file with the following content with each line representing a new object. The text file is stored locally on a PC e.g. C:\data.

Name,Role
PersonA,Administrator
PersonB,Engineer

As we are limited to using a session provided by a third party tool, we cannot use reference jQuery libraries or AJAX.

I would like the content to loop through as follows;

var p = {
            "PersonA" : "Administrator",
            "PersonB" : "Engineer"
        };

for (var key in p) 
{
    if (p.hasOwnProperty(key))
    {
        client = selectedPackage.Elements.AddNew(key, p[key]);
        client.Update();
    }
}

How do I reference a complete path e.g. c:\data\roles.txt and have its content loop through?

3
  • Have you tried using a file:// URL? Not sure it would work, but worth a try Commented Mar 2, 2014 at 23:44
  • FYI - jQuery is pure JavaScript and AJAX is simply a communications concept Commented Mar 2, 2014 at 23:53
  • @Phil - Apologies my mistake. I have updated my post. Commented Mar 2, 2014 at 23:56

2 Answers 2

1

In a browser? The only way to get access to a file on disk is by letting the user select the file with an <input type="file"> and then using the HTML5 File API to read its contents.

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

2 Comments

So where is the script executed? On the server that runs this tool? Do you have any control over it?
It runs in an editor on a local PC. Yes, i have control over the editor.
1

JavaScript is limited, so

  • You can make AJAX connections, but only to the same domain (unless you use CORS).
  • You can't access files in client's machine, unless the client inputs them.

Then, I think the best solution is making the file accessible in your server, and get it using AJAX.

And if you say you can't use AJAX, maybe you could try using an input to load the file, and save it using localStorage for future uses.

1 Comment

Your first dot point isn't necessarily true. See Cross-origin resource sharing

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.