I am trying to modify the href in an anchor before the click is submitted.
However the following creates an infinite loop:
$('.preview').live('click', function(e){
e.preventDefault();
var _this = this;
var content = $('#redactor_content').getCode();
var page_id = $('#page_id').val();
$.ajax({
url: ADMIN_CORE_URL + 'pages/autosave.php',
dataType: 'json',
type: 'POST',
data: {page_id : page_id, content : content},
success: function(data){
var url = $(_this).attr('href') + data.revision_id;
$(_this).attr('href', url);
$(_this).unbind('click').click();
}
});
});
Either I cant get the click to submit or I get the loop.
How do I re-enable the click without the loop?
you could try something like this.
that way the handler only gets executed if the link has class
x(or whatever you want to call it).after the ajax response, remove the class and the click handler shouldn’t be executed anymore.