views:

41

answers:

1

I am trying to read xml into a webpage from another server, and I assume that my problem is Same-Origin Policy, and therefore a cross domain problem.

I have a bit of googling and it seems that jsonp is the way forward. Based on some examples I found here on stackoverflow and another sites, this is what I have, and it does not "hit" the server with the xml. I can view the xml in a browser.

$(document).ready(function(){    
   $.ajax({
        type: 'GET',
        dataType: 'jsonp',                
        url: 'http://192.168.0.106:8111/getconfiguration?',
        success: function (xml) 
        { //do stuff with received xml 
        }});    

Any suggestions? please keep in mind that I am a newbie with regards to JS / JQuery ;o)

+1  A: 

If you have access to code generating the XML on the remote server, you can wrap the whole thing in jsonp.

JSONP is a way of getting around the same-origin policy by obtaining data via using <script tags rather than trying to remotely extract information.

in your getconfiguation script, you would have something like

callback("SERVER GENERATED XML/JSON DATA GOES HERE");

where the callback is specified by the remote call

For instance, if your remote script was php, you would make it look something like this:

'callback';" ?>

Then make run AJAX you provided in your question. What this actually does is dynamically insert a script tag into your page like this:

<script src="http://192.168.0.106:8111/getconfiguation.php?callback=???"&gt;&lt;/script&gt;

jquery fills in the ??? for you with some unique wrapper it generated for your success callback

Jamie Wong