开发者

IE, Jquery, and formy goodness not working

After much searching and tweaking, I cannot for the LIFE of me figure out what is wrong.

Problem: IE does not seem to adhere to my functions set in

$(document).ready($(function() { ...

In FireFox and Chrome the following works:

<form id='submit_new_date'>
<input id='new_date' type='text' />
<input type='submit' value='submit' />
</form>

$("#submit_new_date").live('submit', function (event) {

    var date = $("#new_date").val();
    var employee = $("#employee_id").val();
    var boxcar = $("#boxcar_id").val();
    if (isDate(date)==false) {
        return false;
    }
    event.preventDefault();
        $.ajax({
                url: 'view/create_new_grouping.php',
                type: 'POST',
                data:   'boxcar=' + boxcar + '&employee=' + employee + '&date=' + date,
                success: function(response){
                    $('#content').html(response);
                }
            }); 
    return false;    
    });

In IE, this does not work. It just does the default post action. Which is why I have both return false and preventDefault in there. Any insight would be appreciated.

So I don't think it is an asych problem with ajax, because it doesn开发者_JAVA百科't seem to run the block of code at all. Even putting an alert doesn't change any behavior. Also, the Javascript and html are in separate files obviously.


If you are using using jQuery < 1.4.3 it appears it was a bug in IE if .live('submit') was called after a .live('click')

If upgrading is not an option you could try binding directly to the submit button instead.

$("#submit_new_date input[type='submit']").live("click", function(){
 //stuff
});

A jsfiddle example.

Based upon your comment, if the form is not dynamic (elements are in the dom and not loaded after dom ready) you don't need .live()

$("#submit_new_date").submit( function (event) {
//do stuff
});

Another jsfiddle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜