2013-03-25 45 views
0

我发布的图像和文本数据,工作正常,但在发布过程中,我想显示图像 和同一时间我想禁用后按钮,表单提交图像后应被隐藏并且应该启用发布按钮。想要显示图像,并禁用提交按钮,而阿贾克斯提交

以下是我的代码,在这里我显示图像并禁用发布按钮,但它不工作。

<form id="own_message_post" action="ownmessages" method="post"> 
     <textarea name="message" rows="4" cols="45" id="text_message" placeholder="Update your status"></textarea> 
     <img src="images/loader.gif" alt="posting" id="loading_img" style="visibility: hidden;"> 
     <input id="fileupload" type="file" name="user_post_image" data-url="ownmessages"> 
      <select name="msg_visibility"> 
      <option value="public">Public</option> 
      <option value="friends">Friends</option> 
      <option value="me">Me only</option> 
      </select> 
     <input type="submit" value="Post" id="submit_form_button"> 
     </form> 

<script> 
     // wait for the DOM to be loaded 
     $(document).ready(function() { 
     // bind 'myForm' and provide a simple callback function 
      $('#submit_form_button').click(function() { 
      var a= $('#text_message').val(); 
      if(a=='' || a.length==0) 
      { 
        $('#err').text("Please post your status"); 
        return false; 
       } 
      if(a.length<10) 
       { 
        $('#err').text("minimum 10 characters are required"); 
        return false; 
       } 

     }); 
     $('#own_message_post').ajaxForm(function(data) { 

       $("#loading_img").css("visibility", "visible"); 
       $('#submit_form_button').attr("disabled", true); 
       $('#messages_and_pages').html(data); 
       $('#text_message').val(""); 
       $('#fileupload').val(""); 
       $('#submit_form_button').removeAttr('disabled'); 
       $("#loading_img").css("visibility", "hidden"); 

      }); 
    }); 
</script> 
+0

可能重复http://stackoverflow.com/questions/8140946/how-to-show-a-loading-gif-mean-while -a提交外形是幸福执行的,jQuery的 – Vortex 2013-03-25 06:33:22

回答

0

更改给ajaxForm部分这样的:

var options = { 
      beforeSubmit: function() { 
         // code for disable button and hide/show stuff 
    }, 
      success: function(data) { 
         // code for enable button and show stuff 
    }}; 

    $('#own_message_post').ajaxForm(options);