I am retrieving data from a file, specifically /notes.html
. I am attempting to save the result of the ajax call in a variable, but for some reason it keeps showing up as undefined. However, when I execute the function in chrome developer tools, it displays the content of /notes.html
. Below is my basic code modified to log the data:
var ajax = {};
ajax.result = Array();
ajax.fetch = function(urls,datas){
$.ajax({
url: urls,
type: 'post',
data: datas,
success: function(data){
console.log (data);
}
});
}
ajax.fetch('/notes.html',{});
Here's where the issue lies. If we change the console.log
to be a return
, and then log the ajax.fetch
call, it returns undefined.
Even if I store it in ajax.result
and retrieve it through chrome dev. tools, the content appears there, but I'm unable to utilize it in regular javascript.
The page can be found here. It may appear blank, but you can view what it prints out in the console with the provided code above.