Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
tr00don
Posts: 24
Registered: ‎04-20-2011
My Device: Playbook
Accepted Solution

Reading local txt file => string variable?

Could anyone please point me to a WebWorks example showing how to load the content of a local (=in the app folder) text file into a string variable? Thank you.

Developer
Puzzling
Posts: 51
Registered: ‎10-22-2011
My Device: 9800

Re: Reading local txt file => string variable?

I'm assuming that by "in the app folder" you mean in the bar file. If so, it requires an XHR request. I pulled the following from my app.
        var res;
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                res = xhr.responseText;
            }
        };
        xhr.open("GET",path,0);
        xhr.send();
        // res now contains the contents.