Till the internet explorer 7.0 the ajax request was working fine. but on the new ie 8.0 i tried to use the xdomain object request. But it fails out throwing an error. I dont understand why the error is caused.
Here is my piece of code:
Expand|Select|Wrap|Line Numbers
- <html>
- <script type="text/javascript">
- var xdr;
- function readdata()
- {
- var dRes = document.getElementById('dResponse');
- dRes.innerText = xdr.responseText;
- alert("Content-type: " + xdr.contentType);
- alert("Length: " + xdr.responseText.length);
- }
- function err()
- {
- alert("XDR onerror");
- }
- function timeo()
- {
- alert("XDR ontimeout");
- }
- function loadd()
- {
- alert("XDR onload");
- alert("Got: " + xdr.responseText);
- }
- function progres()
- {
- alert("XDR onprogress");
- alert("Got: " + xdr.responseText);
- }
- function stopdata()
- {
- xdr.abort();
- }
- function mytest()
- {
- var url = document.getElementById('tbURL');
- var timeout = document.getElementById('tbTO');
- if (window.XDomainRequest)
- {
- xdr = new XDomainRequest();
- if (xdr)
- {
- xdr.onerror = err;
- xdr.ontimeout = timeo;
- xdr.onprogress = progres;
- xdr.onload = loadd;
- xdr.timeout = tbTO.value;
- xdr.open("GET", tbURL.value);
- xdr.send();
- }
- else
- {
- alert('Failed to create');
- }
- }
- else
- {
- alert("XDR doesn't exist");
- }
- }
- </script>
- <body>
- <h2>XDomainRequest</h2>
- <input type="text" id="tbURL" value="http://localhost/testajax/testscript.php?p=10" style="width:300px"><br>
- <input type="text" id="tbTO" value="10000"><br>
- <input type="button" onclick="mytest()" value="Get">
- <input type="button" onclick="stopdata()" value="Stop">
- <input type="button" onclick="readdata()" value="Read">
- <br>
- <div id="dResponse"></div>
- </body>
- </html>
I tried changing the URL to ip address,localhost and domain name but it does not work. If any one has any ideas please reply back.
Regards,
Anubhav