Ajax call function after success

I am working on a site where we get information from an XML file. It works fine, but now I need to create a content slider. For this, I will use jCarousel, which claims to be able to do this with dynamically loaded content by calling the callback function.

I cannot, however, do the initial ajax load when I call the function successfully. What am I doing wrong?

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

Am I doing something wrong ??? Or is it a completely different place that I need to see ?:-)

+8
jquery xml ajax jcarousel
source share
3 answers

Use hulabula instead of hulabula () or pass the function directly to ajax parameters:

one.

 $.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) { /* ... */ } }); 
+14
source share

Use $ 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); }); 
+4
source share

You can do it as follows:

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

Just call the function in 'complete' not in 'done' or 'success'

0
source share

All Articles