2011-05-31 19 views
8

Estoy trabajando en un sitio, donde obtenemos información de un archivo XML. Funciona muy bien, pero ahora necesito hacer un control deslizante del contenido. Para hacer esto, usaré jCarousel que dice que pueden hacerlo con contenido cargado dinámicamente, llamando a una función de devolución de llamada.Función de llamada Ajax después del éxito

No puedo, sin embargo, hacer la carga inicial de ajax, cuando llamo a una función en caso de éxito. ¿Qué estoy haciendo mal?

$(document).ready(function() { 
    $.ajax({ 
     type: "GET", 
     //Url to the XML-file 
     url: "data_flash_0303.xml", 
     dataType: "xml", 
     success: hulabula() 
    }); 

    function hulabula(xml) { 
      $(xml).find('top').each(function() { 
       var headline = $(this).find('headline1').text(); 
       var headlineTag = $(this).find('headline2').text(); 

       $(".wunMobile h2 strong").text(headline + " "); 
       $(".wunMobile h2 span").text(headlineTag); 
      }); 

      .............. 

¿Estoy haciendo algo mal ??? ¿O es un lugar totalmente diferente al que debo mirar? :-)

Respuesta

14

Uso hulabula en lugar de hulabula() o pasar directamente a la función de las opciones ajax:

1.

$.ajax({ 
    type: "GET", 
    //Url to the XML-file 
    url: "data_flash_0303.xml", 
    dataType: "xml", 
    success: hulabula 
}); 

2.

$.ajax({ 
    type: "GET", 
    //Url to the XML-file 
    url: "data_flash_0303.xml", 
    dataType: "xml", 
    success: function(xml) { /* ... */ } 
}); 
+0

Cómo pasar objeto de datos? (xml en este caso) –

4

Uso $.when

function hulabula(xml) { 
      $(xml).find('top').each(function() { 
       var headline = $(this).find('headline1').text(); 
       var headlineTag = $(this).find('headline2').text(); 

       $(".wunMobile h2 strong").text(headline + " "); 
       $(".wunMobile h2 span").text(headlineTag); 
      }); 
} 


var ajaxCall = $.ajax({ 
     type: "GET", 
     //Url to the XML-file 
     url: "data_flash_0303.xml", 
     dataType: "xml" 
    }); 

//Use deferred objects 

$.when(ajaxCall) 
.then(function(xml) { hulabula(xml); }); 
+0

La hulabula no está cerrada. ¿Dónde debería estar cerrado? –

+0

@Kenneth: editado la respuesta. – dhinesh

0

Puede hacerlo de esta manera:

$.post("user/get-ups-rates", { cart_id: cart_id, product_id: product_id, service_id:service_id }) 
    .done(function(data) { 
     el.parent().find('.upsResult').html('UPS Shipping Rate Is $'+data.rate); 
    }) 
    .fail(function(data) { 
      el.parent().find('.upsResult').html('<p style="color:red">UPS Service Error Occured. </p>'); 
    }) 
    .complete(function (data) { 
     setShippingOptions(cart_id,product_id,service_id,data.rate); 
    }); 

Sólo tiene que llamar a la función de 'completo' no en 'Hecho' o 'éxito'

Cuestiones relacionadas