javascript - Trouble returning value of nested function using an ajax call -


this question has answer here:

i'm trying append results ajax call paragraph using jquery.

i return variable "myresult" inner getresult function , pass outer buildparagraph function, value returned undefined.

how append value of myresults <p> tag indicated below?

function buildparagraph () {     function getresult(url) {         $.getjson(url, function(data) {          var myresult = data.results;          return myresult;       }     }    var myurl = 'www.mywebsite.com';    getresult(myurl);    $('<p>').html(myresult);  } 

you need have callback function inside ajax success,or easiest way move below code ajax success function

$('<p>').html(data.results); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -