表单上的javascript提交无法正常工作

时间:2014-01-27 11:12:20

标签: javascript php jquery html

我有这个Javscript代码:

<script type="text/javascript">
$(document).ready(function(){
$("#message").hide();
$("#please_wait_box").hide();
$("#updateinvoice").submit(function(e){
    $("#message").hide();
    $("#please_wait_box").show();
    e.preventDefault();
    dataString=$("#updateinvoice").serialize();
    $.ajax({
        type: "POST",
        url: "viewinvoices-popup_go.php",
        cache: false,
        data: dataString,
        success: function(res){
            $("#please_wait_box").hide();
            $("#message").html(res);
            $('#message').fadeIn('slow');
            $('.overlay').fadeOut();
            if(res.indexOf("success")!=-1)
            {
                window.location.href = res.substr(8);
            }
        }
    });
});
});
</script>

和这个HTML:

<div id="message" class="messagebox"></div>
<div id="please_wait_box" class="messagebox">Please Wait...</div>

因此,在表单提交时,它应显示please_wait_box div,然后viewinvoices-popup_go.php页面中的输出应显示在message div

但根本没有显示 - 提交页面上的查询令人兴奋,但

2 个答案:

答案 0 :(得分:-1)

你需要这个:

   $("#updateinvoice").submit(function(e){   
     e.preventDefault();
     // You rst of the code
   });

答案 1 :(得分:-1)

Please try this it will work.

For hiding the message
$('#message').removeClass('messagebox');
$('#message').addClass('hidden');
$('#message').show();

For showing the please_wait_box.
$('#please_wait_box').removeClass('hidden');
$('#please_wait_box').addClass('please_wait_box');
$('#please_wait_box').show();


In your css class

.hidden
{
    display:none;
}


/* use as per your need i have given in general*/

    .please_wait_box
    {
        display:block;
        position:absolute; 
        top:25px;
        left:30px;  
        /*width:100%;*/
        zindex:1000;
        /*opacity:0.5; /* transparency */  
        filter:alpha(opacity=60); 
    }

/* use as per your need i have given in general*/

    .messagebox
    {
        display:block;
        position:absolute; 
        top:25px;
        left:30px;  
        /*width:100%;*/
        zindex:1000;
        /*opacity:0.5; /* transparency */  
        filter:alpha(opacity=60); 
    }


Hope this helps

Thanks