3

I'd like to retrieve and process some XML cross-domain data using AJAX. Here is my code:

$(document).ready(function(){
   $.ajax({
      url: "http://www.synthesiagame.com/scoreboardFeed.aspx?p=c71067ca61fb1c8f3dc9e56dd58cd028_ee7c7e67ec3bc17a08b648fc77802697_f334fca735419b6074f78d82fcc9904d",
      type: "POST",
      dataType: "jsonp xml",
      success: function(data) {
         alert($(data));
         $(data).find('score').each(function(){
            $("#testing").append($(this).attr("points") + "<br />");
         });
      }, error: function(jxhr, status, err) {
            alert("Ajax error: status = " + status + ", err = " + err);
         }
   });
});

This shows the alert() message, but then it doesn't process the XML data. However, if I put a file with XML data on my server as the url it works perfectly.

I've been for two days trying to make this work. I must have read all the questions on this site dealing with similar topics and no answer solved my problem. I'm beginning to think that there might be some problem on their end with the way they present data when they answer requests.

1
  • When you use your own XML, is it exactly the same XML that you are expecting from the url above? Commented Dec 19, 2012 at 17:14

1 Answer 1

1

This is not going to work. The file returned is not wrapped in a function so the JSONP callback can not be called. There is no wrapping function or 'padding'.

JSONP only works if the data coming back is wrapped in a function. Then JQuery will evaluate that function and give you the resulting object.

The only way you can get cross domain XML is by using some kind of proxy to serve the page back in your own domain. The reason why you can use your own xml is because it is in your domain, so there is no conflict.

Here is a good tutorial on how to use a php proxy to do this. If you can't use php you are going to have to find another way to get that file in your domain.

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

2 Comments

Thanks for the information! Could you please revise your link to the tutorial? You pasted the link that was on my code.
whoops. It should be fixed now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.