I need to send click information on my website to a third party server using ajax (json). I am using jquery and I added the click event to certain links. In the click event I am making a json request to a remote server with the location of the click (heat map) and some other information. The problem is that the ajax function doesn't fire in time before the default link action happens. Setting async to false doesn't seem to work on remote ajax calls. I have tried preventDefault(), but then I don't know how to run the default action after the successful ajax call. Here is what I want to do:
$('a').click(submit_click);
function submit_click(e,fireAjax){
e.preventDefault();
cd_$.ajax({
url: jsonUrl, //remote server
dataType: 'json',
data: jsonData,
async: false,
success: function(reply){
//Run the default action here if I have to disable the default action
},
});
}
Any suggestions?