1

I have following text:

"{
  "iv": "QaVlP3rzrSNw3oRLqmXv7Q",
  "v": 1,
  "iter": 1000,
  "ks": 128,
  "ts": 64,
  "mode": "ccm",
  "adata": "",
  "cipher": "aes",
  "salt": "ffGgwesLMEg",
  "ct": "5QjHDbwuLIgYZFWvgIH4J5WZI514zJR0ucsmQ0jljYaOgCKNOWlnrpO0ipEVjQiA7hHfk7T7nXcjN2Yo10U+dGY5DMS+OfvZiGo6/kbBkgpFWEz28uwUl1zIRJ6NBfxULbMjyoUwPuxV05r87U5+H+WEuEiKCP7HWgQH0d68a8AEsvoVah1pDUWlYXom8+TqvTHwmm5Dyyv84h3JN8KHSEnum8ORXDGGNthif3LzirAULRzH0PlsJYrgtj+yOoIWuS0wAKPgwxRkAVchjRoFqEgwfYp+wawLC6oWwj8Mq1ERVyk"
}"

If I use a text file in same directory with this value, using jQuery:

var text = jQuery.get('http://localhost/text.txt');
//This convert text to an Object...

and

JSON.stringify(text)
// returns "{"readyState":1}"

So, is there any method to save this text in a variable?

1
  • If you want it in a variable as a string, just do var foo = JSON.stringify(text); Commented Nov 20, 2016 at 18:22

2 Answers 2

2

You need to use a callback to handle the response and set response type as json.

jQuery.get('http://localhost/text.txt', function(res){
   console.log(res);
}, 'json');

Or use jQuery.getJSON method instead.

jQuery.getJSON('http://localhost/text.txt', function(res){
   console.log(res);
});
Sign up to request clarification or add additional context in comments.

Comments

0
var json_variable = JSON.parse(jQuery.get('http://localhost/text.txt'));

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.