0

I have a nifty little piece of Ajax code that loads in PHP.

http://www.moneyworrier.com/client-stories/

What happens is that when you click on a menu item on the left-hand navigation, it reloads a Div with content appropriate.

What it does however is loop through previous requests, which is bothersome (Click on any left hand item 3x and you will see what I mean). I think I need to find a function that does the equivalent of exit; and clears any post data.

My call in code is:

<a href="#"  class="media video" rel="1">Video</a>

And my JS looks like:

$(document).ready(function () {

    $('a.media').click(function () {
        var usr = $(this).attr('rel');

        $("#displaystories").html('Retrieving..');

        $.ajax({
            type: "POST",
            url: "/client-stories/media.php",
            data: "showcode=" + usr,
            success: function (msg) {
                $("#displaystories").ajaxComplete(function (event, request, settings) {
                    $(this).html(msg);
                });
            }

        });
    });
});
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
Brandrally
  • 803
  • 3
  • 14
  • 24
  • 1
    Please read http://meta.stackexchange.com/questions/125997/something-on-my-web-site-doesnt-work-can-i-just-paste-a-link-to-it . Right now your site is sending 403 forbidden which should illustrate why you should not do this. – Jacob Parker Apr 11 '13 at 15:57
  • 2
    if you need to abort an as yes incomplete Ajax request ( from $.ajax I'm assuming Jquery ) look at this SO question http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery – Dampsquid Apr 11 '13 at 15:58
  • 1
    @JacobParker Cheers for the heads-up, had no-idea. Reading up. Kind regards, Paul – Brandrally Apr 11 '13 at 16:01
  • 1
    Thanks @Dampsquid – Think this might be the answer I'm after. Reading up now. – Brandrally Apr 11 '13 at 16:02

1 Answers1

1

You're binding a new listener to ajaxComplete on every click. Your success callback should just be:

success: function(msg) {  
    $("#displaystories").html(msg);
} 
bfavaretto
  • 71,580
  • 16
  • 111
  • 150