jquery - success: function(data) in ajax doesn't work properly -


i've problem code, when press submit button if ok insertdb should return "success" , set msg variable. message value "nothing"... other output of insertdb work fine... mean output not equal "success". problem??

var interval; function downloadarticle() {   var msg="nothing";   var d = new date();   var time = d.gettime();   var datares=$("#form1").serialize();     if(datares!="url=")   {      $.ajax({         type: "post",         url: "insertdb.php",         data: datares +"&"+ "timestamp=" + time,         success: function (data) {                 msg=data;                 if(msg!="success"){                   $("#resultdialog").text(msg);                   $( "#resultdialog" ).dialog( "open" );                   }                 },             error: function(xhr, ajaxoptions, thrownerror) {             alert(xhr.statustext);             alert(thrownerror);         }            });    } return msg; } function check(){     var d = new date();     var time = d.gettime();     var datares=$("#form1").serialize();         if(datares!="url=" && msg=="success")     {             $.ajax({             type: "post",             url: "check.php",             data: datares+ "&"+"timestamp=" + time,             success: function (data) {             if(data!="لطفا منتظر بمانید!")             {                             window.clearinterval(interval);             }             if(data=="لطفا منتظر بمانید!")             {                 content='<div id="resdiv1" style="width:90%; height:auto; margin-left:5%; margin-right:5%; margin-top:7%; font-size:14pt;" align="center"><strong>لطفا منتظر بمانید!</strong></div>';                     $("#resultdialog").html("");                     $("#resultdialog").html(content);             }              else             {                     content='<div id="resdiv1" style="width:90%; height:auto; margin-left:5%; margin-right:5%; margin-top:5%; font-size:12pt;"><strong>لینک دانلود:</strong></br><div id="download" dir=ltr>'+data+'</div></div>';                     feedback='<div id="feedback" style="width:100%; height:auto; margin-left:5%; margin-right:5%;" dir=rtl><input type="checkbox" id="feedbackbox" name="feedbackbox" value="1">لینک خراب است!</input><input type="button" id="feedbackbutton" name="feedbackbutton" value="گزارش"/></div>';                     $("#resultdialog").text("");                     $("#resultdialog").html(content+feedback);             }             }              });         }         else             window.clearinterval(interval);  } function  start(){  interval=self.setinterval(check,1000);  }  $(document).ready(function (){  $(document).on('click','#submit',function (){     var datares=$("#form1").serialize();         if(datares!="url=")                  {                     var msgdl=downloadarticle();                     if(msgdl=="success")                     {                           start();                           $( "#resultdialog" ).dialog( "open" );                 }                   }   });  }); 

this part of code think never execute

                if(msgdl=="success")                 {                       start();                       $( "#resultdialog" ).dialog( "open" );             } 

if ok insertdb should return "success" , set msg variable.

that's not see in code. you're doing opposite in 'onsuccess' callback :

msg=data; if(msg!="success"){    $("#resultdialog").text(msg);    $( "#resultdialog" ).dialog( "open" ); } 

you printing text if message not 'success'. maybe you'll want add if(msg =="success") instead ?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -