I have a php file somejson.php
that echos a json encoded array
{"jsonone":"first json","jsontwo":"second json"}
I'm trying to access the response with jquery ajax to use this data outside the score of the ajax call. It keeps giving me all kinds of object(Object) or undefined errors.
I'm guessing it's something as easy as wrong syntax, but it's bugging me I thought I'd ask
var mydata = {};
$.ajax({
url: 'somejson.php',
async: false,
dataType: 'json',
success: function (json) {
mydata = json;
mydata[jsonone] = json.jsonone;
mydata[jsontwo] = json.jsontwo;
alert(json[jsonone] . json[jsontwo]);
alert(mydata[jsontwo] . mydata[jsontwo]);
}
});
//later will do some stuff with mydata jsonone and jsontwo
What are all the things I'm doing wrong here?