Skip to content Skip to sidebar Skip to footer

Jquery .load() Function Only Working The First Time

So I have a website I am working on just as a personal website that uses jQuery and jQuery UI Previously I have been using hidden html code and just using jquery to show it. But it

Solution 1:

I got to this item in my search results, when I was trying to have a button both load and refresh the content, and the load was working but the refresh was not working.

Here's a shorter version of the solution, setting Cache to false was the key. Solution found over at this other link, but I'm posting this concept here because if Google dropped me in this item, others looking for the same will also probably find themselves here. Props to John Millikin, make sure to go over to his answer and upvote him:Stop jQuery .load response from being cached

<scripttype="text/javascript">
    $(document).ready(function () {

        $.ajaxSetup({
            // Disable caching of AJAX responsescache: false
        });

        $('.detail-expand').click(function () {

            var detailRowElement = $(this).closest('.session-row-tr').next();
            var detailElement = detailRowElement.find('.detail-row-div');
            var sessionId = detailElement.data("sessionId");

            detailElement.empty();
            detailElement.load('/Admin/WebLogPartial/' + sessionId, function () {
                $.bootstrapSortable(true, 'reversed');
            });

            detailRowElement.show();
        });

    });
</script>

Solution 2:

Anything that depends on the HTML being loaded must be done in the callback function, because the first A in AJAX stands for asynchronous.

$("#2").click(function(){
    $(".jquery2").empty();
    $(".jquery2").load("jqueryEx.html", function() {
        var jquery2 =  $(".jquery2");
        $(".imagearea").html(jquery2);
        $(".jquery2").show(1000);
        $(".title").text("Extending Jquery Example");
    });
});

I'm not really sure what you're trying to do with .html(jquery2), since the argument to .html() is supposed to be a string, not a jQuery object. Maybe you meant:

var jquery2 = $(".jquery2").html();

Post a Comment for "Jquery .load() Function Only Working The First Time"