Home > Web Front-end > JS Tutorial > body text

How to use ajax technology to realize txt pop-up on the page

韦小宝
Release: 2018-01-15 11:39:13
Original
1243 people have browsed it

The following editor will bring you an article on how to use ajax technology to realize txt pop-up on the page. The editor thinks it's pretty good, so now I'll share the ajax source code with you and give it as a reference. If you are interested in ajax, follow the editor to have a look.

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

/*事件会在页面加载完成后触发。*/

<script>

window.onload = function(){

/*获取按钮的id*/

  var oBth=document.getElementById(‘btn&#39;);

/*点击按钮触发的函数*//

  oBth.onclick = function(){

/*打开浏览器*/

    var xhr = new XMLHttpRequest();

/*在地址栏输入地址,这里的1txt代表需要打开的内个txt文件*/

    xhr.open(‘get&#39;,‘1.txt&#39;,true)

/*提交*/

    xhr.send();

/*等服务器返回内容*/

    xhr.onreadystatechange = function(){

      if(xhr.readystate==4){

      alert(xhr.responseText);

}

}

}

}

</script>

<body>
<input type="button" value="按钮" id="btn">
</body>
Copy after login

The above is all the content of using ajax to open a text file through a pop-up window. I hope it will be helpful to everyone! !

Related recommendations:

ajax settings async verification user name exists

How to solve Ajax submission garbled code under IE

Ajax form asynchronous upload file example code detailed explanation

The above is the detailed content of How to use ajax technology to realize txt pop-up on the page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!