0
votes

Note : Please note the question may be silly as I've just begun client-side development. I need to make an XHR POST request to a dynamic link retrieved through JSONP. However for some reasons it doesn't work. Basically the POST url "youtube_url_upload" becomes undefined.

  xhr.open("POST", youtube_url_upload);
Here is the code snippet :
    var get_youtube_service_url ="http://video.example.com/youtubeupload?jsoncallback=?";   
    $.ajax({
            type: "GET",
            url:  get_youtube_service_url,
            dataType: "jsonp",
            cache : false,
            success: function(data) {

                // get youtube
            //  var y_url = data.url;

            var token =  data.token;
            var  youtube_url_upload = data.url + "?nexturl="+encodeURIComponent("http://selling.example.com/youtube.html");
            calltoken(token);

            uploadFile(youtube_url_upload);


            }
          });

     var bytesUploaded = 0;
      var bytesTotal = 0;
......
 function uploadFile(youtube_url_upload) {

      var xhr = new XMLHttpRequest(youtube_url_upload);        
        xhr.upload.addEventListener("progress", uploadProgress, false);
        xhr.addEventListener("load", uploadComplete, false);
        xhr.addEventListener("error", uploadFailed, false);
        xhr.addEventListener("abort", uploadCanceled, false);
        xhr.open("POST", youtube_url_upload);

        xhr.send(fd);

        intervalTimer = setInterval(updateTransferSpeed, 500);
      }
.....
1
are you sure you're getting the right data response? Try console.log(data) in the success callback and see what it shows.Vlad Nicula
as such the code looks ok to me. are you trying to upload video to youtube via ajax??dhaval

1 Answers

0
votes

the success callback get the a string as "data", not object
it's may be a json so use

$.parseJSON ( data )