0

I am writing a js to get a xml from a url but i am not getting any response.Anything I am doing wrong?

  $(document).ready(function () {
            $.ajax({
            type: "GET",
            url: "http://www.w3schools.com/xml/simple.xml",
            dataType: "xml",
            success: function(response)
                {
                    alert(response);
                }
        });


    });

http://jsfiddle.net/4bh0qpb1/1/

2 Answers 2

1

First script syntax error (") that you have fixed, although you can't access following url http://www.w3schools.com/xml/simple.xml using ajax due to CORS (Cross-origin resource sharing) Policy.

Reason Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.w3schools.com/xml/simple.xml. This can be fixed by moving the resource to the same domain or enabling CORS.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks girish how to enable CORS
you can't enable CORS on other domain... it's defined in repose header Access-Control-Allow-Origin: *
But if i do the same request using java like jersey client /webservice client I get a response how is it possible?
use PHP CURL concept.... since you don't have control over W3schools. I know you are looking a javascript solution but it is better to use any server side language like PHP,JAVA to get XML data.
@chiru you should use same domain url and get api response using CURL on server script.
1

You forget to end url parameter with double quote "

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.