Javascript Firefox上未定义jQuery AJAX事件

Javascript Firefox上未定义jQuery AJAX事件,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,此代码适用于Webkit浏览器,但不适用于Firefox。我想我需要把“事件”放在括号里的某个地方,但不确定如何和在哪里 html >下周»; jQuery function reloadweek(){ /*console.log(event.target.dataset.semana)*/ var uploading = jQuery('div#uploading').html('<p><img width="60px" src="<?

此代码适用于Webkit浏览器,但不适用于Firefox。我想我需要把“事件”放在括号里的某个地方,但不确定如何和在哪里

html


>下周»;
jQuery

function reloadweek(){ 
    /*console.log(event.target.dataset.semana)*/

    var uploading = jQuery('div#uploading').html('<p><img width="60px" src="<?php echo get_template_directory_uri();?>/images/loading.gif"/></p>');
    jQuery('#calendar').load("<?php echo get_template_directory_uri();?>/ajaxloader.php #calendar", {
        'week': event.target.dataset.semana,
    }, function() {
        today()
    })
}
函数重载周(){
/*log(event.target.dataset.semana)*/
var uploading=jQuery('div#uploading').html('/images/loading.gif/>');
jQuery(“#calendar”).load(“/ajaxloader.php#calendar”{
“周”:event.target.dataset.semana,
},函数(){
今日()
})
}
您的“onclick”属性应该如下所示:

   <span class="button-prev" role="button" onclick="reloadweek(event);" data-semana=<?php echo $weekprev; ?>>&laquo; Previous Week</span>
javascript:
中的“onclick”处理程序值没有意义

您最好使用jQuery设置事件处理程序:

jQuery(document).on(".button-prev, .button-next", "click", function(event) {
    var uploading = jQuery('div#uploading').html('<p><img width="60px" src="<?php echo get_template_directory_uri();?>/images/loading.gif"/></p>');
    jQuery('#calendar').load("<?php echo get_template_directory_uri();?>/ajaxloader.php #calendar", {
        'week': $(this).data("semana")
    }, function() {
        today();
    });
});
jQuery(document).on(“.button prev,.button next”,“click”,函数(事件){
var uploading=jQuery('div#uploading').html('/images/loading.gif/>');
jQuery(“#calendar”).load(“/ajaxloader.php#calendar”{
“周”:$(this.data(“semana”)
},函数(){
今天();
});
});

处理程序中的
this
的值将(通过jQuery)绑定到单击的元素。那么您实际上根本不需要
事件
,尽管jQuery将确保它被传递。

这取决于调用
reloadweek()
的方式。@Pointy编辑了帖子谢谢,您的第一个解决方案是有效的。但是jQuery解决方案似乎不起作用。另外,您能解释一下为什么使用jQuery方式更好吗?@Jaeeunlee将JavaScript排除在HTML之外被称为“非侵入式JavaScript”。这个想法是你的HTML应该是HTML。通过jQuery设置事件处理程序也更加灵活,因为该库提供了一些有用的便利。感谢您的解释。我会记住的。
function reloadweek(event){ 
jQuery(document).on(".button-prev, .button-next", "click", function(event) {
    var uploading = jQuery('div#uploading').html('<p><img width="60px" src="<?php echo get_template_directory_uri();?>/images/loading.gif"/></p>');
    jQuery('#calendar').load("<?php echo get_template_directory_uri();?>/ajaxloader.php #calendar", {
        'week': $(this).data("semana")
    }, function() {
        today();
    });
});