jquery - use data from ajax call -
i using self host api , want use data ajax call in function, not work. undefinded.
my code:
function checkdata() { $.ajax({ type: "get", url: "http://localhost:8080/api/data" }).success(function (result) { var datareturned = result.statelog; console.log('done' + datareturned); x = datareturned; test(x); }); } setinterval(checkdata, 5000); function test(data) { alert(data); // here undefined }
do know how can use data?
thanks in advanced!
regards, trap
i try , work fine:
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="js/jquery-1.8.1.min.js"></script> <script> function checkdata() { $.ajax({ type: "get", url: "file.data.txt" }).success(function (result) { console.log('readed:' + json.stringify(result)); var datareturned = json.parse(result).statelog; console.log('done ' + datareturned); var x = datareturned; test(x); }); } setinterval(checkdata, 5000); function test(data) { alert(data); // here undefined } </script> </head> <body> </body> </html>
json data(file.data.txt):
{ "statelog":"active" }
Comments
Post a Comment