Bootstrap

android+ajax+get+失败,android - jquery ajax GET request executing twice - Stack Overflow

The issue you are facing is commonly called "bouncing" it's also faced with switches in electronics, when you are pressing and releasing a button the switch is triggered twice, so you need to either set a delay for the function or unbind it once you are done with your click.

You could use Ben Alman's throttle script to debounce your clicks, it's very useful in preventing multiple ajax calls from taking place, combine that with a delay and your issue should be fixed

var debounceClick = $.debounce(test, 1000);

function test() {

console.debug("*");

$.ajax({

type: "GET",

dataType: "json",

url: '/path/to/url',

success: function(data){

console.debug("**");

},

error: function(jqXHR, status, error){

console.debug("*** " + status + " : " + error + " : " + jqXHR.status);

},

cache: false

});

}

Now call the debounceClick function from the link to fix your issue.

Alternatively you could also use simple plain javascript without the throttle plugin to also achieve your result:

var timeout;

function test(){

console.debug("*");

$.ajax({

type: "GET",

dataType: "json",

url: '/path/to/url',

success: function(data){

console.debug("**");

},

error: function(jqXHR, status, error){

console.debug("*** " + status + " : " + error + " : " + jqXHR.status);

},

cache: false

});

}

function click() {

if(timeout) {

clearTimeout(timeout);

}

timeout = setTimeout(test, 1000);

}

In this example, bind the click() function to your link.

;