1
function validateURL(url) {
     if(url){
        $.ajax({
            url: "/check_urlstatus/",
            type: "post",
            data: {url:url,csrfmiddlewaretoken: '{{ csrf_token }}'}                  
        }).done(function(data){
           if(data=="ok"){
             return true;
           }else{
             return false;
           }
        });       
     }else{
         return false;
     }       
 }

function check(){
  var web = $.trim($('#web').val());   
  var status = validateURL(web);
  alert(status); 
}

ajax is returning ok String. But this alert inside check() is giving undefined. I guess, the scope of .done() callback is local?! or what am I doing wrong?

doniyor
  • 36,596
  • 57
  • 175
  • 260

0 Answers0