title: ajax() call in javascript function
body: <p>i have a jquery .click() function that executes an .ajax() method call</p>
  
  <pre><code>$(".btn-play").live("click", function () {
              //set globalSortNumber
              globalSortNumber = $(this).parents("[sortnumber]").attr("sortnumber");//.attr("value") ; //change should be some type of input like mediaid //see if its possible to add the sortID to the handle span
  //            alert(globalSortNumber);
              //set title
  
              //set mediaID
              var mediaID = $(this).parents("[mediaid]").attr("mediaid");
  //          alert(mediaID);
              //ajax query to get link and excute code to launch music
              $.ajax({
                  type:"POST",
                  url:"ajax/AB3Ajax.asmx/GenerateLink",
                  data:"{'mediaId':" + mediaId + ",'userId':" + "0" + "}",
                  contentType:"application/json; charset=utf-8",
                  dataType:"json",
                  success:function (msg) {
                      if (msg.d != "") {
                          playsong(msg.d,null);
                          }
                          else {
                              soundManager.stopAll();
                              //look at what is already in place in mystudio
                          } 
                  },
                  error: function (err) {
                  //add code later look at what is already in place in mystudio
                  } 
              })
  </code></pre>
  
  <p>when the .ajax() method executes succesfully it calls a javascript function</p>
  
  <pre><code>function playsong(sortNumber,url) {
          if (soundManager.supported()) {
              globalSortNumber = sortNumber;
              var aSoundObject = soundManager.createSound({
                  id: 'mySound' + sortNumber,
                  url: url,//'/Music/mafiamusicpt2rickross.mp3',
                  whileplaying: function () {
                      if (count == 0) {
                          if (this.position &gt; 1000) {
                              this.pause();
                              pos = this.position;
                              count++;
                              this.resume();
                          }
                      } else if (count == 1) {
                          soundManager._writeDebug('old position: ' + pos);
                          soundManager._writeDebug('new position: ' + this.position);
                          // See that this.position is less than pos!
                          count++;
                      }
                  },
                  onfinish: function () {
                      //find the next song in the list
                      //var nextSongPosition=
                      this.destruct();
  
                      $.ajax({
                  type:"POST",
                  url:"ajax/AB3Ajax.asmx/GenerateLink",
                  data:"{'mediaId':" + mediaId + ",'userId':" + "0" + "}",
                  contentType:"application/json; charset=utf-8",
                  dataType:"json",
                  success:function (msg) {
                      if (msg.d != "") {
                          playsong(msg.d,null);
                          }
                          else {
                              soundManager.stopAll();
                              //look at what is already in place in mystudio
                          } 
                  },
                  error: function (err) {
                  //add code later look at what is already in place in mystudio
                  } 
              })
                      playsong(sortNumber++,url)
                  }
              });
              aSoundObject.play();
          }
      }
  </code></pre>
  
  <p>as you can see i have an .ajax() method inside my javascript function, is this possible?</p>
  
  <p>I am creating loop that starts on the finish listener of the soundmanager object.  So when I need to make the ajax call to get he next url I need.  If my way isnt correct can you please tell me what is the best way to accomplish what i am trying to do.</p>