Bug Tracker

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#10365 closed enhancement (duplicate)

onprogress ajax

Reported by: anonymous Owned by: jaubourg
Priority: low Milestone: 1.next
Component: ajax Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by jaubourg)

I wanna know if you have some api of progress event on sending XMLHttpRequest. I have used one example of https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest to do the function on the ajax core on jquery.min. I think its a good sugestion to do that in the next jquery version.

// Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
//  Progresso de upload
var divporcentagem = $j("#porcentagem");

function onProgress(e) {
  var percentComplete = ( (e.loaded / e.total)*100 ).toFixed(0); 
  divporcentagem.empty();
  divporcentagem.append(percentComplete+"%");
}  

xhr.upload.onprogress = onProgress;
xhr.send( ( s.hasContent && s.data ) || null );

I think its not possible to atach lik a complete:function{} or success.

Thanks.

Change History (6)

comment:1 Changed 8 years ago by jaubourg

Component: unfiledajax
Description: modified (diff)
Milestone: None1.next
Owner: set to jaubourg
Priority: undecidedlow
Status: newassigned

comment:2 Changed 8 years ago by anonymous

Actually i think is not a try/catch function just a fuction atched to the xhr object but i undertand that ou guys make an exception for it so i did some api based on jquery thanks for the answer.

comment:3 in reply to:  description Changed 8 years ago by anonymous

Replying to anonymous:

I wanna know if you have some api of progress event on sending XMLHttpRequest. I have used one example of https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest to do the function on the ajax core on jquery.min. I think its a good sugestion to do that in the next jquery version.

// Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
//  Progresso de upload
var divporcentagem = $j("#porcentagem");

function onProgress(e) {
  var percentComplete = ( (e.loaded / e.total)*100 ).toFixed(0); 
  divporcentagem.empty();
  divporcentagem.append(percentComplete+"%");
}  

xhr.upload.onprogress = onProgress;
xhr.send( ( s.hasContent && s.data ) || null );

I think its not possible to atach lik a complete:function{} or success.

Thanks.

Actually i think is not a try/catch function just a fuction atched to the xhr object but i undertand that ou guys make an exception for it so i did some api based on jquery thanks for the answer.

comment:4 in reply to:  2 Changed 8 years ago by anonymous

Replying to anonymous:

Actually i think is not a try/catch function just a fuction atched to the xhr object but i undertand that ou guys make an exception for it so i did some api based on jquery thanks for the answer.

(function(jQuery){

jQuery.ajaxmrQUERY = function(options) {

var configuracoes = {

url : null, type : null, data : null, async: true, acao : null, ContentType : "text"

}

var opcoes = jQuery.extend(configuracoes,options); criarAjaxmr(opcoes);

};

var criarAjaxmr = function(opcoes){

var requisicao = new XMLHttpRequest(); requisicao.upload.onprogress = opcoes.progresso; requisicao.onload = opcoes.successo; requisicao.onerror = opcoes.errore;

requisicao.onreadystatechange = function() {

if(requisicao.readyState==4) {

if(requisicao.status==200) {

if(opcoes.ContentType=="text") {

opcoes.respostadarequisicao(requisicao.responseText);

}

if(opcoes.ContentType=="json") {

opcoes.respostadarequisicao(JSON.parse(requisicao.responseText));

}

}

}

}

requisicao.open(opcoes.type, opcoes.url, opcoes.async);

if(opcoes.acao=="search") {

requisicao.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); requisicao.send($j.param(opcoes.data));

} else {

requisicao.send(opcoes.data);

}

}

})(jQuery);

comment:5 Changed 7 years ago by jaubourg

Resolution: duplicate
Status: assignedclosed

comment:6 Changed 7 years ago by jaubourg

Duplicate of #9883.

Note: See TracTickets for help on using tickets.