2012-02-15 46 views
0

我正在尝试编写显示任务及其状态的任务窗体的代码。这是我的形式。更新内容中的bug ajax

enter image description here

如果我点击状态内容的选择菜单将与三个选项CompletedIn ProgressWaiting for client confirmation出现。如果我选择一个选项并按下输入,它将在数据库中更新。如果状态更新为completed,则选择框不应显示在点击事件中。我的问题是,如果我更新状态完成,然后单击出现选择菜单相同的状态。但如果我修改并刷新页面,它工作正常。我需要它刷新页面才是正确的。

这是我的PHP代码

<?php 
      if($fetchstatus == 'Completed'){ 
      echo 'Completed'; 
      } 
      else{?> 
      <span id="status"><?php echo $fetchstatus; ?></span> 
      <select id="<?php echo $fetchtaskid; ?>" style="width:110px;"> 
      <option value="In progress">In progress</option> 
      <option value="Completed">Completed</option> 
      <option value="Waiting for client confirmation">Waiting for client confirmation</option> 
      </select> 
      <?php 
      } 
      ?> 

这是我的AJAX脚本

$(document).ready(function(){ 
     var eventFlag=false; 
     var originalText=''; 
     $('.updatetask tr td span#status').click(function(e){ 
      e.stopImmediatePropagation(); 
      $(this).siblings().show().focus(); 
      $(this).hide(); 
      eventFlag=false; 
      originalText=$(this).siblings().val(); 
     }); 

     $('.updatetask tr td select').blur(function(e){ 
      if(!eventFlag && validate($(this))) doAjax($(this)); 
      else 
      { 
       $(this).siblings().show(); 
       $(this).hide(); 
      } 
     }); 

     $('.updatetask tr td select').keypress(function(e){ 
      e.stopImmediatePropagation(); 
      var code = (e.keyCode ? e.keyCode : e.which); 
      if(code==13) 
      { 
       if(validate($(this))) 
       { 
        doAjax($(this)); 
        eventFlag=true; 
       } 
       else 
       { 
        $(this).siblings().show(); 
        $(this).hide(); 
       } 
      } 
     }); 

     function validate(input) 
     { 
      console.log(input.val()+" "+originalText); 
      if(input.val()!='' && input.val()!=originalText) 
      return true 
      else return false; 
     } 

     function doAjax(input) 
     { 
      var formData="proId="+input.attr('id')+"&text="+input.val(); 
       $.ajax({ 
        type: "POST", 
        url: "update_taskstatus.php", 
        data: formData, 
        success: function(data){ 
         if(data==1) 
         { 
          input.siblings().text(input.val()).show(); 
          input.hide(); 
          if(input.val()=='completed') 
          { 
           input.siblings().unbind('click'); 
          } 
         } 
         else 
         { 
          input.siblings().show(); 
          input.hide(); 
          alert("something Wrong !"); 
         } 
        }, 
        error:function (xhr, ajaxOptions, thrownError){ 
         alert("Error:"+xhr.status+" "+thrownError); 
        } 
       }); 
     } 

    }); 

我怎么能纠正?

+0

@designersvsoft,看看。 – 2012-02-15 06:13:12

回答

1

正如你已经改变了我的代码,我给你昨天所以我有点迷茫,不知道我当前的代码是否将工作或没有,但我从猜测试试这个,让我知道结果

if(data==1) 
{ 
    input.siblings().text(input.val()).show(); 
    input.hide(); 
    if(input.val()=='Completed') 
    { 
     input.siblings().unbind('click'); 
    } 
} 

改变do ajax函数,只有第一个if块,希望它足够清楚。

+0

非常感谢您的努力heera。我用你的代码更新了我的问题中的ajax脚本。但它不能正常工作。请看我的问题。 – designersvsoft 2012-02-15 06:23:21

+0

更改完成后在我的代码里面完成if。 – 2012-02-15 06:27:00

+0

令人惊叹。你说对了。非常感谢你。我很抱歉没有注意到拼写。再次感谢您的努力。 – designersvsoft 2012-02-15 06:31:40