Reputation: 56
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?
Upvotes: 1
Views: 43
Reputation: 2947
var json_variable = JSON.parse(jQuery.get('http://localhost/text.txt'));
Upvotes: 0
Reputation: 115222
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);
});
Upvotes: 2