Saturday, 15 January 2011

javascript - What is wrong with this code for XHR? -



javascript - What is wrong with this code for XHR? -

this first code making xhr request, trying debug can't find fault is. using google chrome, , wamp server. url using html file in own computer

i sorry problem in helping me in solving problem. result expect?

i expect browser opent localhost/css/margins/margin.html

but happens page goes blank click on "click me!".

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>project 1</title> <script type="text/javascript"> var a; //creating object request named "a" if(window.xmlhttprequest) { = new xmlhttprequest(); } else if(window.activexobject) { a= new activexobject("microsoft.xmlhttp"); } function response() //this function utilize callback function { if(a.readystate==4) { if(a.status==200) { alert("perfect"); } else { alert("getting improper response"); } } else { alert("not getting response"); } } function open() //making request { a.open('get', "localhost/css/margins/margin.html", true); a.onreadystatechange = response; a.send(null); } </script> <span onclick="open();">click me!</span> //this onclick event phone call function create request. </head> <body> </body> </html>

your code fine, url entered not global, directs relative path of current page.

change a.open('get', location.protocol+"//localhost/css/margins/margin.html", true);

javascript ajax xmlhttprequest

No comments:

Post a Comment