Home  >  Article  >  Web Front-end  >  Ajax realizes txt text popping up on the page

Ajax realizes txt text popping up on the page

php中世界最好的语言
php中世界最好的语言Original
2018-04-03 17:40:491718browse

This time I will bring you the ajax implementation of txt text popping up on the page. What are the precautions for ajax implementation of txt text popping up on the page. The following is a practical case, let's take a look.

Use ajax technology to click the button and display the content in the TXT text on the page through the pop-up box

/*事件会在页面加载完成后触发。*/
<script>
window.onload = function(){
/*获取按钮的id*/
  var oBth=document.getElementById(‘btn');
/*点击按钮触发的函数*//
  oBth.onclick = function(){
/*打开浏览器*/
    var xhr = new XMLHttpRequest();
/*在地址栏输入地址,这里的1txt代表需要打开的内个txt文件*/
    xhr.open(‘get',‘1.txt',true)
/*提交*/
    xhr.send();
/*等服务器返回内容*/
    xhr.onreadystatechange = function(){
      if(xhr.readystate==4){
      alert(xhr.responseText);
}
}
}
}
</script>
<body>
<input type="button" value="按钮" id="btn">
</body>

I believe you have mastered the method after reading the case in this article. For more exciting things, please pay attention to php Other related articles on the Chinese website!

Recommended reading:

Ajax submits data to the backend database to implement user registration

How to achieve level 2 with Ajax combined with PHP Linkage

A must-read analysis of Ajax technology components and core principles for beginners

The above is the detailed content of Ajax realizes txt text popping up on the page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn