#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 )
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 11 years ago by
Component: | unfiled → ajax |
---|---|
Description: | modified (diff) |
Milestone: | None → 1.next |
Owner: | set to jaubourg |
Priority: | undecided → low |
Status: | new → assigned |
comment:2 follow-up: 4 Changed 11 years ago by
comment:3 Changed 11 years ago by
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 Changed 11 years ago by
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 11 years ago by
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
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.