Write a button to display the contents of the local TXT file in the specified div after clicking
Create a new test.txt in the local area, it is good to write some content.
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8" />5 </Head>6 <Body>7 <inputtype= "button"ID= "Btn_test"value= "Test"onclick= "Javascript:testajax (' test.txt ');" />8 <BR/><BR/>9 <DivID= "Testdiv">hello,world!</Div>Ten One <Script> A functionTestajax (request_url) { - varXMLHTTP= NULL; - Try{ the varXMLHTTP= NewXMLHttpRequest (); - }Catch(e) { - Try{ - varXMLHTTP= NewActiveXObject ("Microsoft.XMLHTTP"); + }Catch(e) { - Alert ("Your Browser is not a support AJAX"); + } A } at - if(XMLHTTP) { - Xmlhttp.open ("GET", Request_url,true); - Xmlhttp.onreadystatechange= function (){ - if(Xmlhttp.readystate== 4 &&Xmlhttp.status== $){ - document.getElementById ("Testdiv"). InnerHTML=Xmlhttp.responsetext; in } - }; to Xmlhttp.send (NULL); + }Else{ - Alert ("Error"); the } * } $ </Script>Panax Notoginseng </Body> - </HTML>
Ajax transfer local TXT file content