tags:

views:

1121

answers:

4

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

             }
         });

}

+1  A: 

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

         }
     });
Mark Biek
A: 

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

Try to manually load that URL. It could be deployed to the root directory, but still not availalbe and returning an error code.
Mads Hansen
Even when I am giving the URL like 'http://dirname/PlaylistJson.aspx its giving the same error..onFailure
What happens when you go to that URL in your browser?
Mark Biek
its working fine..I mean when I pass the Querystring like PlayListJson.aspx?id=32 it display the result in Json Format
+1  A: 

Can you put the code the generates the JSON in a try-catch block? Where the catch block returns the exception's message. This way we can see what is failing.

Also if PlaylistJSON.aspx is in your project directory root you don't need the beginning slash:

new Ajax.Request('PlaylistJSON.aspx', ...

Side note on design: You may want to consider doing AJAX calls to methods inside web services rather than to ASP.NET pages. This avoids waiting for the the whole page event life cycle to execute.

thoughtcrimes
+1  A: 

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.

Serhii