binding ajax function with "live" gives error, yet works with "click"
In this function, when I use it I get error on the whole code block! (in chrome console)
however when I replacelive
with click
it works fine, how is it?
$("form[0] :submit").live(function(event) {
event.preventDefault();
var search_data = { company : $("form[0] :text").val() }
$.ajax({
type: "POST",
url: "<?= site_url('pages/search') ?>",
data: se开发者_开发问答arch_data,
success: function(msg){
alert( "Data Saved: " + msg );
}
});
});
When you use .live()
, you have to specify which kind of event you want to bind a handler for. For most situations, it looks like this:
$('form[0]').live('submit', function() {
...
});
You can also use a space-separated list of event types, or an object with event type : function pairs for multiple events / functions.
精彩评论