search

Home  >  Q&A  >  body text

return false Why does the a tag still jump?

<script>

window.onload=function(){

document.getElementsByTagName('a')[0].onclick=function(){

var request=new XMLHttpRequest();

                                                                                                              ’     ’ ’ s                     out out way out through out way out through outce out out out out out out out out out out off to ’'s' ‐ ‐ ‐ww's' ;

request.send(null); //Send Ajax request to the server, the get here does not need to pass parameters

request.onreadystatechange=function(){ //Continuously monitor the server side Response

if(request.readyState==4&&request.status=200){ //The request status is 4 and the request code is 200, which means the server effect is successful

document.getElementsByTagName('h3' )[0].innerHTML=request.responseText //Get the text information and display it at the h3 position

}

}

return false ; / /Cancel the default jump behavior of a tag

}

}

</script>

WeavingWeaving2013 days ago1582

reply all(1)I'll reply

  • Mr.jiang

    Mr.jiang2020-02-13 09:49:40

    request.readyState==4&&request.status=200

    Look carefully at this code

    reply
    0
  • Cancelreply