成功后Ajax调用函数

我正在一个网站上工作,我们从XML文件中获取信息。 它工作得很好,但现在我需要制作内容的滑块。 为此,我将使用jCarousel声称他们可以通过调用回调函数来使用动态加载的内容。

但是,当我成功调用函数时,我无法进行初始的ajax加载。 我究竟做错了什么?

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

我做错了什么??? 或者这是一个我必须要看的完全不同的地方? 🙂

使用hulabula而不是hulabula()或将函数直接传递给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) { /* ... */ } }); 

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

你可以这样做:

  $.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('

UPS Service Error Occured.

'); }) .complete(function (data) { setShippingOptions(cart_id,product_id,service_id,data.rate); });

只需在“完成”中调用该函数,而不是“完成”或“成功”