Permalink
Browse files

Use ajax function instead of getJSON

  • Loading branch information...
1 parent 8951918 commit da971d331c598654399c2e50452184efa0f1758c @johanoskarsson committed Feb 28, 2012
Showing with 21 additions and 8 deletions.
  1. +1 −1 lib/sources/lastfm_source.rb
  2. +3 −2 playlistify.rb
  3. +17 −5 public/assets/js/application.js
@@ -21,7 +21,7 @@ def get_tracks(from_collection, user)
when :loved_tracks
lastfm.user.get_loved_tracks(user)
end
-
+
tracks.map {|track| {:track => track["name"], :artist=>track["artist"]["name"]}}
end
end
View
@@ -30,7 +30,8 @@
session[:tracks] = tracks
tracks.to_json
rescue Exception => e
- '{"error" : "Failed to playlistify: ' + e.to_s + '"}'
+ puts e.backtrace
+ [500, '{"error" : "Failed to playlistify: ' + e.to_s + '"}']
end
end
@@ -54,7 +55,7 @@
'{"complete" : "true"}'
rescue Exception => e
puts e.backtrace
- '{"error" : "Failed to playlistify: ' + e.to_s + '"}'
+ [500, '{"error" : "Failed to playlistify: ' + e.to_s + '"}']
end
end
@@ -44,19 +44,31 @@ $('#rdio-target').on('shown', function () {
// TODO not sure how to execute this code only on the right page. this will do
$(document).ready(function () {
if($('#working-on-it').is(':visible')) {
- $.getJSON("/add_to_playlist.json",
- function(data) {
+ $.ajax({
+ url: "/add_to_playlist.json",
+ dataType: "json",
+ statusCode: {
+ 500: function(data) {
+ $('#the-error').html(data)
+ $('#error-msg').show()
+ }
+ },
+ error: function(data){
+ $('#the-error').html(data)
+ $('#error-msg').show()
+ },
+ success: function(data){
$('#working-on-it').hide()
- if(data["complete"] == "true") {
+ if(data["complete"] === "true") {
$('#masthead').hide()
$('#done').show()
} else {
$('#the-error').html(data["error"])
$('#error-msg').show()
}
- }
- );
+ }
+ });
}
});

0 comments on commit da971d3

Please sign in to comment.