I have a piece of code where there's a link and a input button both calling a same onclick function. However, they behave differently.
<input type="button" onclick="undelete_this("profile.php", 42)" value="Undelete">
<a href="" onclick="undelete_this("profile.php",42)"><strong>here</strong></a>
function undelete_this(url, id){
if(confirm("Are you sure you want to undelete this record?")){
if(id!=="" && id!=0){
var info = 'id=' + id +"&action=undelete";
$.ajax({
type: "GET",
url: url,
data: info,
success: function(){
window.location.href = ($(location).attr('pathname')+"?enter=false&id="+id);
},
error: function(jqXHR, exception, realexception) {
alert(jqXHR.responseText+" "+realexception);
}
}
)
}
}
return false;
}
when the button is clicked, the ajax status is success; but when the link is clicked, the ajax status is error (error code = 0) and the responseText is blank.
Is there anyone have an idea why this is happening?