2 Replies - 3440 Views - Last Post: 18 April 2016 - 09:48 PM

#1 Desertt   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 182
  • Joined: 27-October 13

Jquery.load variable repeat

Posted 16 April 2016 - 01:54 AM

Hi i'm using this script to display result in pagination results

$(".Alphabeticals").click(function() {
            var id = this.id;
            $('#district option[value=NoValue]').attr('selected', 'selected');
            $(".yellow, .display-numb").show();
            $(".Alphabeticals").removeClass('selected');
            $(this).addClass('selected');
            $("#Brand_Name").html("All Restaurants Starting With Letter (" + id + ")");
            var pageInitial = "<?php echo $thisPage;?>";
            $("#results").load(pageInitial + "/Mobile/Search/LetterResult.php", {
                "letter": id,
            });
            $("#results").on("click", ".paginating a", function(e) {
                e.preventDefault();
				$(".loading-div").show();
                var page = $(this).attr("data-page");
                $("#results").load(pageInitial + "/Mobile/Search/LetterResult.php", {
                    "letter": id,
                    "page": page
                }, function() {
					$(".loading-div").hide();
				});
            });
        });


If i alert(id) after the .click function it alert the right value ( Values lays between A to Z ) but if i alert after the .on("click",....) it alert all the previous value till the last one chooses
e.g :
if i click on A both alert fire "A" if i click on C the first alert fire "C" but the second one alert "A", "C" if i chooses G the first alert also fire "G" and the second one fire "A", "C", "G" how can i make the pagination send only the element chooses without sending all the previous values

Is This A Good Question/Topic? 0
  • +

Replies To: Jquery.load variable repeat

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Jquery.load variable repeat

Posted 18 April 2016 - 05:18 AM

Quote

if i click on A both alert fire "A" if i click on C the first alert fire "C" but the second one alert "A", "C" if i chooses G the first alert also fire "G" and the second one fire "A", "C", "G"

that’s because on each click, you add another click handler to the #results element.

not sure why you want to fire two almost identical AJAX loads in one go anyways.
Was This Post Helpful? 0
  • +
  • -

#3 Desertt   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 182
  • Joined: 27-October 13

Re: Jquery.load variable repeat

Posted 18 April 2016 - 09:48 PM

It's obvious that i used the two alert to see the repeated ID from where its fired from the event click or pagination click, but i found the solution, i added
$("#results").off("click", ".paging a"); just before
$("#results").on("click", ".paginating a", function(e) {
and it works.

This post has been edited by Desertt: 19 April 2016 - 01:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1