0

I am trying to read the text of a file with Javascript/JQuery.

However I am unable to return the data to my main function. The "console.log" works but not the "return str".

MyFile = function() {

};
MyFile.readFile = function(file) {
    var str = "";
    $.get(file, {}, function(data) {
        str = data;
        console.log(str);
    }, "text");
    return str;
};
Talon06
  • 1,756
  • 3
  • 27
  • 51
  • you just defined `MyFile` as a `function`, so why would `MyFile.readFile` work? – DLeh Apr 29 '15 at 16:52
  • 1
    DLeh functions in javascript are objects as well and can have properties so MyFile.readFile will be perfectly legal. – devconcept Apr 29 '15 at 16:55

0 Answers0