Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/03/2013, 13:30
underwebinfo
 
Fecha de Ingreso: septiembre-2012
Ubicación: Buenos aires
Mensajes: 110
Antigüedad: 11 años, 7 meses
Puntos: 9
Sonrisa Jquery Plugin: Object #<Object> has no method

Tengo un inconveniente con un plugin jquery que hice sobre XHR leve 2.

el plugin en cuestion:

Código Javascript:
Ver original
  1. (function($){
  2.        
  3.        
  4.         $.AjaxPrepare = function(option){
  5.                
  6.                 // Definiendo opciones
  7.                 options = $.extend($.AjaxPrepare.default,option);
  8.                
  9.                 // Instanciando
  10.                 var ajax        = new XMLHttpRequest();
  11.                 var form        = new FormData();
  12.                
  13.                 // Condicionales
  14.                 var swiTch      = false;
  15.                 var GET         = null;
  16.                
  17.                 // Definiendo metodo
  18.                 if(options.method=='' || !options.method){
  19.                        
  20.                         options.method='POST';
  21.                        
  22.                 }
  23.                
  24.                 // Insertando datos pasados por post.
  25.                 if(options.insert.length>0 && options.method=='POST'){
  26.                        
  27.                         for(var i=0;i<options.insert.length;i++){
  28.                                
  29.                                 form.append(options.insert[i][0],options.insert[i][1]);
  30.                                
  31.                         }
  32.                        
  33.                 }
  34.                
  35.                 // Parseando datos ingresados por get.
  36.                 if(options.insert.length>0 && options.method=='GET'){
  37.                        
  38.                         GET='?';
  39.                        
  40.                         for(var i=0;i<options.insert.length;i++){
  41.                                
  42.                                 GET += options.insert[i][0]+'='+options.insert[i][1];
  43.                                
  44.                                 if((i+1)!==options.insert.length){
  45.                                        
  46.                                         GET+='&';
  47.                                
  48.                                 }
  49.                         }
  50.                         swiTch=true;
  51.                 }
  52.                
  53.                 // Definiendo forma de abrir
  54.                 if(swiTch && GET!==null){
  55.                        
  56.                         ajax.open(options.method,options.url+GET,true);
  57.                
  58.                 }else{
  59.                        
  60.                         ajax.open(options.method,options.url,true);
  61.                        
  62.                 }
  63.                
  64.                 // Estados
  65.                 ajax.onreadystatechange = function(){
  66.                        
  67.                         if(ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3){
  68.                                
  69.                                 alert(options.onLoad());
  70.                                 options.onLoad();
  71.                                
  72.                         }
  73.                        
  74.                         if(ajax.readyState==4 && ajax.status==200){
  75.                                
  76.                                 alert(options.onLoaded(ajax.response));
  77.                                 options.onLoaded(ajax.response);
  78.                                
  79.                         }
  80.                        
  81.                         if(ajax.readyState==4 && ajax.status==404){
  82.                                
  83.                                 options.onError();
  84.                        
  85.                         }
  86.                
  87.                 };
  88.                
  89.                 // Progreso de peticion
  90.                 ajax.upload.onprogress = function(e){
  91.                        
  92.                         if(e.lengthComputable){
  93.                                
  94.                                 var porcentaje=Math.ceil((e.loaded/e.total)*100);
  95.                                
  96.                                 options.onProgress(porcentaje);
  97.                        
  98.                         }
  99.                        
  100.                 };
  101.                
  102.                 // Forma de envio
  103.                 if(swiTch && GET!==null){
  104.                        
  105.                         ajax.send(null);
  106.                        
  107.                 }else{
  108.                        
  109.                         ajax.send(form);
  110.                        
  111.                 }
  112.                
  113.         }
  114.        
  115.         // Opciones por default
  116.         $.AjaxPrepare.default = {
  117.                
  118.                 insert          : [],                                   // [ ['name',value],['name','value'] ] name: nombre con el que identificas desde php. value: valor que obtendras en php [string | int | file].
  119.                 url                     : String,                               // Url php, etc... procesador de informacion. [String].
  120.                 method          : String,                               // Metodo a emplear para la peticion ['POST' | 'GET'].
  121.  
  122.                 onLoad          : function(){},                 // onLoad(){}           Funcion equivalente a readyState[1,2,3].
  123.                 onLoaded        : function(response){}, // onLoaded(){}         Funcion equivalente a readyState[4] y Status[200].
  124.                 onProgress      : function(progress){}, // onProgress(){}       Funcion que devuelve el procentaje de avance de la peticion.
  125.                 onError         : function(){},                 // onError(){}          Equivalente a readyState[4] y Status[404]
  126.                
  127.         }
  128.        
  129.        
  130.        
  131. })(jQuery);







En Uso


Código Javascript:
Ver original
  1. function handleFileSelect(evt){
  2.                
  3.         // ---- Prevencion
  4.         evt.stopPropagation();
  5.         evt.preventDefault();
  6.  
  7.         // ---- Datos
  8.         var content             = $('article.Photos');
  9.         var category    = $('article.Photos').attr('id');
  10.         var files               = evt.dataTransfer.files; // FileList object.
  11.        
  12.         // Bucle for
  13.         for(var i = 0; i<files.length; i++){
  14.                
  15.                
  16.                 $.AjaxPrepare({
  17.                        
  18.                         insert  : [['category',category],['photo',files[i]]],
  19.                         url             : 'http://localhost/Nayla2/admin/UploadPhotos',
  20.                         method  : "POST",
  21.                        
  22.                         // Cargando...
  23.                         onLoad  : (function(){
  24.                                
  25.                                 var html = '<div class="Foto Uploading" id="Foto_'+i+'"><img src=""><span id="Process_'+i+'"></span></div>';
  26.                                 content.append(html);
  27.                                
  28.                         }),
  29.                        
  30.                         // Terminado...
  31.                         onLoaded: (function(response){
  32.                                
  33.                                 // Datos Json
  34.                                 var json = eval("("+response+")");
  35.                                
  36.                                 // Reemplazando el progress by el delete button
  37.                                 $('span#Process_'+i).replaceWith('<input type="button" value="X" class="delete_image" id="'+json.id+'">');
  38.        
  39.                                 // Reemplazando la imagen en base64 by image true
  40.                                 $('div#Foto_'+i+' > img').replaceWith('<img src="'+json.image+'">');
  41.                                
  42.                                 // Eliminando clase uploading
  43.                                 $('div#Foto_'+i).removeClass('Uploading');
  44.                                
  45.                         }),
  46.                        
  47.                         // Error...
  48.                         onError : (function(){
  49.                                
  50.                                 $('#Foto_'+i).remove();
  51.                                 alert('No se pudo subir: '+files[i].name);
  52.                                
  53.                         }),
  54.                        
  55.                         // Progreso...
  56.                         onProgress: (function(result){
  57.                                
  58.                                 var result = (100-result);
  59.                                
  60.                                 $('span#Process_'+i).css('height',result+'%');
  61.                                                                
  62.                         })
  63.                        
  64.                 });
  65.                
  66.                 // ----- Prevista
  67.                 $.ImagePreview({
  68.                        
  69.                         file    : files[i],
  70.                         onLoad  : function(image){
  71.                                
  72.                                 $('div#Foto_'+i+' > img').attr('src',image);
  73.                                
  74.                         }
  75.                        
  76.                 });
  77.                                                
  78.                
  79.         }
  80.        
  81. }




Error del uso:

Uncaught TypeError: Object #<Object> has no method 'onProgress' PluginAjaxXhr2.js
Uncaught TypeError: Object #<Object> has no method 'onLoaded'


como puedo hacer para que me tome como metodos las funciones y no como objetos el plugin? o como puedo solucionar el error xD