-1

My idea was to create one function that returns the value of the call at rest service.

Code from inside function:

.....

var dddd;
 $.ajax({
     type: "GET",
     url: "http://localhost:8084/GetSomeRest/asdf/ddd/arbol/1",  
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     async: "false", // with this line add solved
     success: function (dataaa) {
         // do something
       dddd= dataaa.name;
         alert(dddd);// here has value
     }}); 
alertt(dddd); //here is null
.....

What is the problem? Any help is welcome.

JJJ
  • 32,902
  • 20
  • 89
  • 102
  • possible duplicate of [How to return the response from an AJAX call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Rory McCrossan Nov 21 '13 at 12:52

1 Answers1

0
var dddd;

 $.ajax({
     type: "GET",
     url: "http://localhost:8084/GetSomeRest/asdf/ddd/arbol/1",  
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function (dataaa) {
         // do something
       dddd= dataaa.name;
         alert(dddd);// here has value
     }}); 
alert(dddd); --> this is fired before assigning value through ajax

Ajax call is not completed when you call that alert outside ajax call

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107