and how did you manage to write the AJAX code in the first place?
Please help me on this AJAX code
Collapse
X
-
Use the following Code It will work..
Code:<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Ajax Demo...</title> <style type="text/css"> .box{border:1px solid black;padding:10px} </style> <script type="text/javascript"> var asyncRequest; function getContent() { try { if (window.XMLHttpRequest) { asyncRequest=new XMLHttpRequest(); } else { asyncRequest=new ActiveXObject("Microsoft.XMLHTTP"); } //asyncRequest=new XMLHttpRequest(); asyncRequest.open('POST',"b.html",true); asyncRequest.onreadystatechange = stateChange; asyncRequest.send(null); } catch(exception) { alert('Request Failed'); } } function stateChange() { document.getElementById('contentArea').innerHTML=asyncRequest.responseText; if(asyncRequest.readyState==4 ){ document.getElementById('contentArea').innerHTML=asyncRequest.responseText; } if(asyncRequest.status==200) { document.getElementById('contentArea').innerHTML=asyncRequest.responseText; } } function clearContent() { document.getElementById('contentArea').innerHTML=''; } </script> </head> <body> <h1>Moue over a player for More Information</h1> <img src="sachin.jpg" height="42" width="42" onmouseover='getContent()' onmouseout='clearContent()'/> <div class="box" id="contentArea"/> </body> </html>Comment
-
-
you have not done much mistake..I think in line no 25.
asyncRequest.op en('POST',"b.ht ml",true); here previously you used 'GET' just i changed it to POST.
And also for your info if you get any problems while doing with AJAX or with JAvaScript you put alert("message" ) where you get some doubt then easily you can find out the problem what happened.Comment
-
-
see post #12What was the mistake done by me?
that's not the reason. if you look at the code you see that there are no parameters used (it's a request for a static page), hence there is no difference between GET & POST.I think in line no 25.
asyncRequest.op en('POST',"b.ht ml",true); here previously you used 'GET' just i changed it to POST.Comment
-
You are right Mr.Dormilich , but when I tried this code in my browser it clearly show the error message method GET is not supported..
And also without using any webserver how can we send a dynamic URL in asyncRequest.op en('POST',"b.ht ml",true);
If we use within a server then only we can get the dynamic content..Comment
-
if GET were not supported, you wouldn't even be able to load a website.but when I tried this code in my browser it clearly show the error message method GET is not supported..
using JavaScript? since you said "send an URL" this comes clearly from the client side so whether or not you use a webserver is irrelevant.And also without using any webserver how can we send a dynamic URLComment
-
I am talkin about relative URL not the direct URL.. Even we can use a direct URl in html also ...
We will Ajax to make our page as asynchronus by using our resources not the websites...
And for your info u try the above code with using GET and tell me whether u got the answer or not,,,,Comment
Comment