2

I have this url which get list of objects as a xml

https://test/ab

I want to call this using only javascript I try this

function loadXMLDoc() {


    xhttp.open("GET", "https://test/ab", true);


    }
    xhttp.send();
    }

please help

It gives status correct and ready state correct but it give me the responseText is empty

but when I try this url on my browser it works fine

sara adly
  • 297
  • 1
  • 5
  • 19
  • It will depend on whether it supports CORS – Arun P Johny Mar 17 '16 at 09:26
  • If CORS is not enabled you can't use ajax to get content of the page that have different domain. – jcubic Mar 17 '16 at 09:27
  • how can I know that this is support CORS? @ArunPJohny – sara adly Mar 17 '16 at 09:30
  • @jcubic So what shall I DO? – sara adly Mar 17 '16 at 09:30
  • 2
    your second `onreadystatechange` will overwrite the first one. you need to put that document line where your comment is right now. and open the developer tools see any errors. – Roland Starke Mar 17 '16 at 09:31
  • @RolandStarke developer tools say that error XMLHttpRequest cannot load https://portal.test.net/Qest/api/groups/2/members/inable/ab. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:61914' is therefore not allowed access. – sara adly Mar 17 '16 at 09:35
  • You can check network tab in developer tools to see if CORS is enabled (Access-Control-Allow-Origin header) if it's not present then the only option is to create server side proxy script that will read the content of the page. – jcubic Mar 17 '16 at 09:36

1 Answers1

0

If CORS is the problem try this addon in Chrome. You can go through this Question to know more possible solutions to this problem.

Community
  • 1
  • 1
Ankur Rana
  • 88
  • 9
  • Sorry can't understand what you mean – sara adly Mar 17 '16 at 09:32
  • but you should note that the site will only work for you then (or others that have this addon), so i would not recommend it – Roland Starke Mar 17 '16 at 09:33
  • Yes, thats one of the problems with this method. – Ankur Rana Mar 17 '16 at 09:41
  • @Ankur It works for me on chrome only now after add the extension – sara adly Mar 17 '16 at 09:41
  • Please refer to this [Question](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) to know possible solutions to this problem. If you want to make it work on other browsers, you'll have to install similar addons for them as well. Also remember that this addon only resolves this issue on your browser ( as Ronald stated). – Ankur Rana Mar 17 '16 at 09:49