-2

Why this javascript function not work on ie7 and 8 ?

When user click button , it's will display PLEASE WAIT.... and hide and then display TEST

I test on firefox and chrome, It's OK

But not work on IE7 and 8 , How can i do that ?

index.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form id="myForm" name="send_ask" action="test_e.php" method="post">
    <button id="sub">Send</button>
    <span id="loading" style="display:none;">PLEASE WAIT.......</span>
    <span id="result" style="display:none;"></span>
</form>



<script type="text/javascript">
$('#myForm').submit(function(e){
    e.preventDefault();
    $.ajax({
        url: $("#myForm").attr("action"),
        data: $("#myForm :input").serializeArray(),
        type: 'post',
        dataType: 'html',
        success: function(data){
            $("#result").html(data);
        },
        beforeSend: function(){
            document.getElementById("sub").disabled = true;
            document.getElementById("loading").style.display="inline";
            $("#result").hide()
        },
        complete: function(data){
            $("#result").show()
        }
    });
});
</script>

test_e.php

TEST

1 Answers1

1

Well first thing I see if the button is not a submit button so not sure how the others are submitting the form.

<button id="sub" type="submit">Send</button>
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • 1
    If a button is inside a form, it will trigger a submit even without `type="submit"` unless it's explicitly set to `type="button"`. Odd but true! – Sam Hanley Nov 20 '14 at 15:35