JP Edwards
JP Edwards

Reputation: 87

Ajax Bringing in a div and turning it into a slider

I have used Ajax to load a div with id of slider.

I want to use the jquery statement $('#slider').orbit();

Since this is loaded via Ajax, I am not sure how to do this. In the past, I have used the on function when I have had to add click events. However, since this just needs to run without any click, hover etc. I am not sure how to do it?

Can anyone help please?

Upvotes: 0

Views: 79

Answers (2)

Anthony Grist
Anthony Grist

Reputation: 38345

When performing a jQuery AJAX call you can (and usually should) specify a success function, which runs when a successful response from the server is received. Simply execute your code inside of that:

$.ajax({
    url: url,
    success: function(response) {
        // some code
        $('#slider').orbit();
    }
});

If you're using one of the shorthand jQuery functions - such as $.get() or $.post() - then the success function is passed as one of its parameters:

$.post(url, function(response) {
    // some code
    $('#slider').orbit();
});

Related docs:

Upvotes: 1

thatidiotguy
thatidiotguy

Reputation: 9011

Use the ajax callback function to run that code.

You can find the syntax in the relevant function in the JQuery api.

http://api.jquery.com

Upvotes: 1

Related Questions