Reputation: 573
I have anchor link with click and href events. I need to run click event first then once complete the event it should call href to access action class. I have updated the sample code in jsfiddle like complete the click event , it should forward to stackoverflow.com. But its not forwarding after click.
Please advise.
$(document).ready(function () {
$("div.actions").append('<a id="excelExport" class="actionButton" alt="Export to Excel" title="Export to Excel" href="listexport">click me</a>');
$('div.actions').on('click', '#excelExport', function (e) {
e.preventDefault();
callajax();
});
});
function callajax() {
jQuery.ajax({
url : '',
data :
}
Upvotes: 0
Views: 431
Reputation: 177685
Since you prevent the link, you need to send this.href to the CallAjax function and do location=href
in the success method
This is of course assuming you'll change the alert to an Ajax call later
callajax(this.href);
function callajax(href) {
var URL = href;
$.get("something",{"URL":URL },function(URL){
// url is returned from server
location.href=URL;
});
}
OR
function callajax(href) {
var URL = href;
$.get("something",{"URL":URL },function() { // reuse url passed to function
location.href=URL;
});
}
Upvotes: 1