user1765107
user1765107

Reputation: 11

javascript read file and put content as variable

I am a beginner at javascript, so please before saying duplicate or anything, please try to help me by pointing me in the right direction to where I should seek the answers. I see many questions like this but none relative to my need. So, i have to ask..

I have a javascript, with

this.a.$a = "content";

Now somewhere in that script, I have

a.target_url = this.a.$a;

That this.a.$a was a string that we manually added via input box.

What i need is a function to read a file contents, convert it into a string, and print the value as a variable in this.a.$a.

The file name is Test.txt, with long URI as http://www.mydomain.com/test.txt

The file contents is : Neque porro quisquam est qui dolorem ipsum quia dolor sit amet

I have tried

$.get("http://www.mydomain.com/test.txt", function(data) { 
    this.a.$a = data
});

But what I got was [object] [Object].

Can someone explain this to me please?

Thanks in advance.

Upvotes: 1

Views: 695

Answers (1)

roacher
roacher

Reputation: 666

You should try outputing the variable with console.log, then check firebug to see what the object looks like. Though my gut tells me this should fix your problem:

$.get("http://www.mydomain.com/test.txt", function(data) { 
    this.a.$a = data.d
});

Upvotes: 1

Related Questions