0

I have a node server that is running on different port "81", i want to get the response for the Ajax GET call then check the response if it has some kind value return true for accept attribute for droppable callback function.

This is the code i have:

$(document).ready(function(){

    $('.user').draggable();
    $('.user').droppable({

      accept: function() {

      $.ajax("http://127.0.0.1:81/").done(function(data){
          if(data.toString() == "success")
             return true;
          else
             return false
               });        
            }, 
             activeClass: 'ui-state-hover',
             hoverClass:  'ui-state-active'
             drop: function(event, ui){
                  $(this).addClass("ui-state-highlight").find("b").html("User deleted.");       
                }

    });

});

});

And how can i get the response from data. Note: In the Node.js server i'm returning a text with res.end("success");.

0x01Brain
  • 798
  • 2
  • 12
  • 28
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Quentin Dec 21 '15 at 08:44

1 Answers1

2

If you are using Express js, you problem will be solved. for example use the below code

res.send({"status":"success"}) 

or

res.json({status:"success"});

try like this will work

Nalla Srinivas
  • 913
  • 1
  • 9
  • 17