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); } .....