In Ajax, the execution is successful but the page is still refreshed

The page code is this <a href="" id="1">remove</a>

when i use ajax


$("a").click(function(){

$.get("Servlet","opr=del",callBack);
});

function callBack(data){
$("#myDiv").append("12312313132123123");
if(data!="true"){
alert("Deletion failed!");
}else{
alert("Deleted successfully!");
} }

However, although viewing the database will delete successfully, this page is refreshed.

We all know that using ajax is to keep the page from being refreshed. If it is refreshed, then ajax will lose its meaning.

After checking, it turned out to be <a href="" id="1">delete</a> when clicking, something should be written in the href, otherwise it would be equivalent to refreshing the page, so it should be written as this <a href="#" id="1">delete</a>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325395605&siteId=291194637