Why I can't alert x value after this ajax request? I work with error function.
var x;
$.ajax({
url: 'http://gdata.youtube.com/feeds/api/videos/' + code,
type: 'get',
dataType: 'json',
success: function(data) {
console.log('Result 1: ');
console.log(data.responseText);
},
error: function(e) {
var text = e.responseText;
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, "text/xml");
var titleXml = xmlDoc.getElementsByTagName('title')[0];
var contentXml = xmlDoc.getElementsByTagName('content')[0];
title = titleXml.childNodes[0];
content = contentXml.childNodes[0];
x = title;
}
});
alert(x);
if I make alert local in error function everything work fine, but I need to alert x value after ajax.