2

I'm trying to get some xml information from a service that is not mine. Basically, the user will authenticate on the other service and my script should go get the information using it authentication cookie via cross-site.

I'm using jquery to do that, and I can see that the response I want to process is returned by the service (via firebug), the thing is that I'm using jsonp to do the call, so jquery returns a parsing error.

I've tried all the solutions that I encountered to do this kind of operation, like YQL and proxy server.

My frustration in here is that I'm seeing the response I want but jquery just don't give me the raw information.

I know that I'm calling a function that expects json response, but isn't any workaround or other way to this? like xmlp xD.

$.ajax(
        {
            url: "serviceurl",

            dataType: 'jsonp', //I've tried 'jsonp xml'


            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            success: function()
            {
                alert('Load was performed.');
            },

            error: function(jqxhr,error) 
            { 
                alert('Failed!'); 
            },

        });

EDIT: Here is the output from the server

<User>
 DVD_PT
</User>
<Apps>
 <App>
   <name>Last.fm Scrobbler</name>
 </App>
</Apps>

Thanks

DVD
  • 1,744
  • 3
  • 17
  • 34

1 Answers1

0

It simply isn't possible to request XML from a cross-domain source unless the other domain supports CORS.

You must use some sort of proxy such as YQL, as you have already mentioned.

The response you are seeing when you set the datatype to JSONP is inside of a <script> tag. For example, you are getting this:

<script src="http://example.com/note.xml"></script>

where note.xml is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

which will of course throw an error because it is not valid javascript.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • I'm aware of that. I can't use proxies because I can't send the auth cookie, since I don't have access to it. Now I curious, how to the browser fetch the data? I'm asking this because if I request the url normally I can see the data, isn't any way to emulate that behavior? – DVD Feb 17 '12 at 17:30
  • @DVD - No because there are security issues with that. The browser specifically prevents you from receiving data from a different domain unless the domain returns CORS headers. Couldn't you just request a page on your server with the auth key, then have your server perform the cross-domain http request? – Kevin B Feb 17 '12 at 18:20
  • I could do that, and I probably will since I can't find another way, but the idea was just a simple script that read the data and shows information in a pretty way than the original xD – DVD Feb 17 '12 at 18:28