0

I'm rookie when it comes to Ajax and jQuery and needs some help...

The following url produces an xml-file that I want to use on my page: http://ws.spotify.com/search/1/track?q=foo

When I use firebug it seems like nothing comes back. What have I done wrong?

This is what my code looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
     <head>    
         <title></title> 
         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> 
         <script type="text/javascript"> 
         $(document).ready(function(){
            $.ajax({
                url: 'http://ws.spotify.com/search/1/track?q=foo',
                type: 'GET',
                contentType: "application/xml; charset=utf-8",
                error: function(){
                    alert('Error loading XML document');
                },
                success: function(xml){
                    alert("success");
                    $(xml).appendTo("#result");                   
                }
            });
        });
         </script> 
     </head> 
     <body> 
        <div id="result">
        </div>       
     </body> 
 </html>
3
  • 3
    Is that xml file on the same domain as the script you're calling it from? Commented Apr 22, 2010 at 19:15
  • When you say nothing comes back, I assume you mean that your success callback is getting called, but there's no data. Is that right? Commented Apr 22, 2010 at 19:45
  • A pure XML reply would not display in the browser. Commented Apr 22, 2010 at 19:52

4 Answers 4

2

Is your web page where the JS is running also from ws.spotify.com? Otherwise, you will run into the browser's restrictions to prevent cross-site scripting by using the same origin policy. You can use data of type jsonp to get around this issue. Ajaxian provided a post on a workaround that you can hopefully use. It doesn't use jQuery, but it may help.

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

Comments

1

Seems your success function may be a little off:

success: function(data) {
    alert("success");
    $('#result').html(data);
  }

Comments

0

Try to use JSON return format instead of XML, there is some information concerning your case here: XmlHTTPRequest: "XML Parsing Error: no element found"

Comments

0

Can I suggest you also use HTTPFox to look at what's happening between your script and the server

Comments

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.