1

hi actually i am trying to get the content of any page which is provided...i am able to content if the page is in same server if i provide another server name its not working.i know we can easily achieve in jquery but i need it in js only... below the code i using...

<script>
 function loadXMLDoc()
 {
  var xmlhttp;
 if (window.XMLHttpRequest)
     {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
     }
   else
    {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
    xmlhttp.onreadystatechange=function()
     {alert(xmlhttp.status);
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
    //alert("SADF");
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
          }
     }
  var url=document.getElementById("url").value;

  xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
     </script>

<div id="myDiv"></div>
<input type="text" name="url" id="url"/>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

thanks in advance...

sasi kanth
  • 2,637
  • 4
  • 17
  • 29
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin Aug 13 '13 at 06:13
  • "i know we can easily achieve in jquery but i need it in js only" — jQuery doesn't have any features that make it significantly simpler do perform cross-domain Ajax. – Quentin Aug 13 '13 at 06:15
  • Is there any error or exception?? – Deepu--Java Aug 13 '13 at 06:37

1 Answers1

-1

You cant make cross domain request from Javascript. There are two solutions to this;

  1. Either use IFrame for this
  2. Use XDomainRequest for making the request

Refer this link for more details over XDomainRequest:

MSDN

Abhishek Jain
  • 2,597
  • 1
  • 18
  • 12
  • Iframes have similar security restrictions to XHR, so that won't work. XDomainRequest is the non-standard solution for old-Internet Explorer, not a current solution. – Quentin Aug 13 '13 at 06:14
  • No, while the accepted answer (not written by me) on the duplicate question does make mention of iframes, they are only small parts of the solutions discussed. – Quentin Aug 13 '13 at 06:24