Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击href发送ajax帖子_Javascript_Jquery_Joomla2.5 - Fatal编程技术网

Javascript 单击href发送ajax帖子

Javascript 单击href发送ajax帖子,javascript,jquery,joomla2.5,Javascript,Jquery,Joomla2.5,单击链接时,我需要通过ajax发送post。问题是,由于打开了链接,请求被丢弃 jQuery('#pagination a').click(function(){ jQuery.post('index.php?option=com_component', {checked_sites_for_session: jQuery('.selected-site input[type="checkbox"]').map(function () {return this.value

单击链接时,我需要通过
ajax
发送
post
。问题是,由于打开了链接,请求被丢弃

jQuery('#pagination a').click(function(){
    jQuery.post('index.php?option=com_component',
        {checked_sites_for_session: jQuery('.selected-site input[type="checkbox"]').map(function () {return this.value;}).get()}
    ).success(function(){window.location = jQuery(this).attr('href')});
    console.log(jQuery(this).attr('href'));
    return false;
});
但同样的问题是(多亏了joomla)url中的问题——它类似于
/~user/joomla/index.php/view sites?view=sites&page=2
——正如您看到的,它从斜杠开始,但真正的链接是
http://localhost/~user/joomla/index.php/view sites?view=sites&page=2
,但在源代码中我对此有问题

    jQuery('#pagination a').click(function(e){
    e.preventDefault();
var me=this;
        jQuery.post('index.php?option=com_component',
            {checked_sites_for_session: jQuery('.selected-site input[type="checkbox"]').map(function () {return this.value;}).get()}
        ).success(function(){window.location = jQuery(this).attr('href')});
        console.log(jQuery(me).attr('href'));
        return false;
    });
这有什么问题

    jQuery('#pagination a').click(function(e){
    e.preventDefault();
var me=this;
        jQuery.post('index.php?option=com_component',
            {checked_sites_for_session: jQuery('.selected-site input[type="checkbox"]').map(function () {return this.value;}).get()}
        ).success(function(){window.location = jQuery(this).attr('href')});
        console.log(jQuery(me).attr('href'));
        return false;
    });

使用native element.href将获得包括域在内的整个href,而不仅仅是attributes值,而且在$,post函数中使用的
这个
关键字也存在范围问题:

$('#pagination a').on('click', function(e){
    e.preventDefault();
    var self = this;
    $.post('index.php?option=com_component',
        {checked_sites_for_session: $('.selected-site input[type="checkbox"]').map(function () {
                 return this.value;
            }).get();
        }
    ).success(function(){
        window.location = self.href;
    });
});

从您发布的链接来看,它们看起来根本不一样,因此您可能必须找到解决方案,因为某些CMS解决方案使用重写等。使用native元素。href将获得整个href,包括域,而不仅仅是属性值,在$,post函数中使用的
this
关键字也存在范围问题:

$('#pagination a').on('click', function(e){
    e.preventDefault();
    var self = this;
    $.post('index.php?option=com_component',
        {checked_sites_for_session: $('.selected-site input[type="checkbox"]').map(function () {
                 return this.value;
            }).get();
        }
    ).success(function(){
        window.location = self.href;
    });
});

从您发布的链接来看,它们看起来根本不一样,因此您可能必须找到解决方案,因为某些CMS解决方案使用重写等。

返回false
阻止默认操作并停止传播。真正的问题在于
返回false
阻止默认操作并停止传播。真正的问题在于
这个