Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use ajax function instead of getJSON

  • Loading branch information...
commit da971d331c598654399c2e50452184efa0f1758c 1 parent 8951918
Johan Oskarsson authored February 27, 2012
2  lib/sources/lastfm_source.rb
@@ -21,7 +21,7 @@ def get_tracks(from_collection, user)
21 21
     when :loved_tracks
22 22
       lastfm.user.get_loved_tracks(user)
23 23
     end
24  
-      
  24
+    
25 25
     tracks.map {|track| {:track => track["name"], :artist=>track["artist"]["name"]}}
26 26
   end
27 27
 end
5  playlistify.rb
@@ -30,7 +30,8 @@
30 30
     session[:tracks] = tracks
31 31
     tracks.to_json
32 32
   rescue Exception => e
33  
-    '{"error" : "Failed to playlistify: ' + e.to_s + '"}'
  33
+    puts e.backtrace
  34
+    [500, '{"error" : "Failed to playlistify: ' + e.to_s + '"}']
34 35
   end
35 36
 end
36 37
 
@@ -54,7 +55,7 @@
54 55
     '{"complete" : "true"}'
55 56
   rescue Exception => e
56 57
     puts e.backtrace
57  
-    '{"error" : "Failed to playlistify: ' + e.to_s + '"}'
  58
+    [500, '{"error" : "Failed to playlistify: ' + e.to_s + '"}']
58 59
   end
59 60
 end
60 61
 
22  public/assets/js/application.js
@@ -44,19 +44,31 @@ $('#rdio-target').on('shown', function () {
44 44
 // TODO not sure how to execute this code only on the right page. this will do
45 45
 $(document).ready(function () {
46 46
   if($('#working-on-it').is(':visible')) {
47  
-    $.getJSON("/add_to_playlist.json",  
48  
-      function(data) {  
  47
+    $.ajax({
  48
+      url: "/add_to_playlist.json",
  49
+      dataType: "json",
  50
+      statusCode: {
  51
+        500: function(data) {
  52
+          $('#the-error').html(data)
  53
+          $('#error-msg').show()
  54
+        }
  55
+      },
  56
+      error: function(data){
  57
+        $('#the-error').html(data)
  58
+        $('#error-msg').show()
  59
+      },
  60
+      success: function(data){
49 61
         $('#working-on-it').hide()
50 62
 
51  
-        if(data["complete"] == "true") {
  63
+        if(data["complete"] === "true") {
52 64
           $('#masthead').hide()
53 65
           $('#done').show()
54 66
         } else {
55 67
           $('#the-error').html(data["error"])
56 68
           $('#error-msg').show()
57 69
         }
58  
-      }  
59  
-    );    
  70
+      }
  71
+    });
60 72
   }
61 73
 });
62 74
 

0 notes on commit da971d3

Please sign in to comment.
Something went wrong with that request. Please try again.