我有一個jquery + ajax代碼來跟蹤點擊我網站上的廣告鏈接。這對於測試目的:如何獲得href屬性的值並在ajax中使用
$(document).ready(function(){
$(".myadlinks").on("click",function(e){
e.preventDefault();
var d = {id:$(this).attr('id')};
$.ajax({
type : 'GET',
url : "adlinktracking.php",
data : d,
success : function(responseText){
if(responseText==1){
alert('click is saved OK');
window.location.href = $(this).attr('href');
}else if(responseText==0){
alert('click can't be saved.');
}
else{
alert('error with your php code');
}
}
});
});
});
當我點擊廣告鏈接,它顯示警報:單擊保存確定的,但那麼它不會重定向到預期的網址。我認爲這行代碼window.location.href = $(this).attr('href');
有問題。因爲當我試圖用「http://www.google.com」替換$(this).attr('href');
。有用。
請幫助...非常感謝
歡呼聲它適用於我......非常感謝 – 2015-03-13 08:38:15