当我点击一个链接时,我需要通过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)在<a href="index.php?option=com_component&view=sites&.'.$option.'page='.$left.'"//....`中-它像/~user/joomla/index.php/view-sites?view=sites&page=2一样-正如你所看到的,它从斜杠开始,但真正的链接是http://localhost/~user/joomla/index.php/view-sites?view=sites&page=2,但在源代码中我有url
所以我需要一些“多用途域名解析解决方案”,或者干脆阻止joomla改变我的网址。
发布于 2012-11-21 18:20:59
使用原生element.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解决方案使用重写等。
发布于 2012-11-21 18:20:45
这方面的问题
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;
});https://stackoverflow.com/questions/13490992
复制相似问题