javascript - parameter url in XMLHttpRequest.open() AJAX -


i'm practicing in ajax , i'm stuck html page respondes user's click on button, showing specific html file;

this code:

<!doctype hmtl> <html> <body>     <button type="button" name="button1" >button1</button>     <button type="button" name="button2" >button2</button>     <button type="button" name="button3" >button3</button>     <button type="button" name="button4" >button4</button>     <hr/>     <p id="demo">visualize document here!</p> </body>  <script>  var documenti= document.getelementbytagname("button"); for(var i=0; i<documenti.length; i++) {     documenti[i].onclick= loaddoc; }  function loaddoc() {     var httpreq= new xmlhttprequest();     httpreq.onreadystatechange= caricadocumento;     httpreq.open("get", "this file i'm trying visualize!" ,         true);     httpreq.send(); }  function handleresponse(e){     if(e.target.status==200 && e.target.readystate==xmlhttprequest.done) {         document.getelementbyid("demo").innerhtml= e.target.rensponsetext;     } } </script> </html> 

if want use html file on pc, how can specified in attribute url??? if have correctly understand, url parameters url of document require server, if document doesn't reside on server?

if want use html file on pc, how can specified in attribute url???

you need url.

this either file: scheme url (which many browsers block xmlhttprequest security reasons) or, if run webserver on computer, http: (or https:) url.

the latter option more reliable, pick web server software , use that.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -