0

God day, i copied this expample from thislink in stackoverflow and it works fine, how do i now turn it into a variable that i can use throughout the rest of my project as i have put in the exapmle below, it wont give me the values i get inside the function, it writes undefined.

function something(callback){

$.ajax({
         type: "GET",
         contentType: "application/x-www-form-urlencoded",
        url: "http:url.com",
        dataType: 'json',
        success: 

            callback
            // console.log(data);
        //  console.log(JSON.parse(data));

            // window.location.replace("mainkedaabuild.html"+"?#"+data );
        ,
        error: function()
        {
             $('#output').html("Unable to connect");
            // window.location.replace("404kedaa.html");
        }


    });

};


    var Blue = something(function (data) {


data; return data;

})

    console.log(Blue);
Waldi
  • 39,242
  • 6
  • 30
  • 78
user1951739
  • 135
  • 1
  • 9
  • https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Gerardo Furtado Mar 18 '18 at 11:48
  • Hi Gerardo, thanks for the speedy reply, while i have read the reply and it make total sense to me, even with the example at the bottom, i am not equipt enough to write my own working solution, can you please right me one with a usable Promise! – user1951739 Mar 18 '18 at 11:58
  • Glad to see that the link helped you. However, the correct action here is closing your question as a duplicate. – Gerardo Furtado Mar 18 '18 at 12:15

0 Answers0