Badmate
Badmate

Reputation:

Problem with Ajax.Request using JSon and Prototype

I am using the following function to load a PlayList of Songs from 'PlayListJSON.aspx' but somethings seems wrong,evrytime OnFailure is getting called, I am unable to debug it further. any help would be really gr8.

Player.prototype.loadPlaylist = function(playlistId, play) {
  req = new Ajax.Request('/PlaylistJSON.aspx?id=' + playlistId, {
    method: 'GET',
    onSuccess: function(transport, json) {
      eval(transport.responseText);

      player.setPlaylist(playlist.tracklist, playlist.title, playlistId);
      player.firstTrack();

      if (play) player.playSong();
    },
    onFailure: function() {
      //error
    }
  });
}

Upvotes: 2

Views: 1948

Answers (3)

Serxipc
Serxipc

Reputation: 6699

If you are developing in windows install Fiddler. With Fiddler you will be able to see exactly what request is doing the Ajax call and what response comes from the server. This way you will know if the url is right, or if the server is responding some status code different from 200/OK.

Upvotes: 1

Mark Biek
Mark Biek

Reputation: 150749

Generally, OnFailure gets called when the page you are calling out to can't be reached for some reason.

Are you positive that the URL /PlaylistJSON.aspx is valid?


Have you tried passing the parameters argument instead of specifying them as part of the url?

req = new Ajax.Request('/PlaylistJSON.aspx', 
    { 

        method: 'GET',    
        parameters:  {
                     'id': playlistId
                     },
        onSuccess: function(transport,json){                                                                                    

            eval(transport.responseText);                              

            player.setPlaylist(playlist.tracklist,playlist.title, playlistId);
            player.firstTrack();

            if (play)
                player.playSong();  

         },
         onFailure: function() {
           //error

         }
     });

Upvotes: 1

Badmate
Badmate

Reputation:

Yes the Page PlayListJSon.aspx is in the root directory.

Upvotes: 0

Related Questions