How can I make an AJAX call to this API?

21 views
Skip to first unread message

Richard Hamilton

unread,
May 27, 2015, 12:13:12 PM5/27/15
to rdio...@googlegroups.com
I have been banging my head against the wall for the last hour trying to figure out how in the world I'm supposed to make an API call to the service.

This works

<form action="http://rdio-service.herokuapp.com//search?" method="get" target="_blank">
  Enter Keywords: <input type="text" name="q"><br>
  <button>Find songs</button>
</form>

I see the JSON output in another tab, but I'd like to store the JSON data in a variable. I've tried using AJAX requests for this but to no avail. I can't even get a message letting me know whether or not I've failed.

$(document).ready(function() {
    $("#get-json").click(function() {
      $.ajax({
        url: "http://rdio-service.herokuapp.com//search?q=jay",
        type: "GET",
        dataType: 'JSON',
        success:function() {
          alert('success');
        },
        error:function() {
          alert('error');
        }
      });
    });
});


<form id="search">
  Get Token:
  <input id="query" type="text"></input>
<button id="get-json">Get Results</button>
</form>

For whatever reason, my AJAX request doesn't return anything. Does anyone know how I can make an AJAX call to get data from the server and store that data in a variable?

Devin Sevilla

unread,
Jun 15, 2015, 5:38:27 PM6/15/15
to rdio...@googlegroups.com
Hi Richard!

The issue is with your callbacks, they don't accept parameters. The
`success` function will be called with three parameters: `data,
textStatus, jqXHR`[1]. The first parameter, `data`, is what you're
looking for. I'd modify the success function to be:

function(data, textStatus, jqXHR) {
console.log(data, textStatus, jqXHR);
}

That will log the results to the javascript console so you can see the results.

[1]: http://api.jquery.com/jquery.ajax/

Cheers

--
Devin Sevilla
API Engineer, Rdio Inc.
http://rdio.com/people/devin_s/
> --
> You received this message because you are subscribed to the Google Groups
> "Rdio API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rdio-api+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rdio-api/0af9aecc-ac03-4c29-ba76-3a12cfbd2186%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages