How to call an AJAX function on anchor tag?

前端 未结 1 946
一生所求
一生所求 2020-12-18 17:51

I\'m using PHP, jQuery, AJAX, Smarty for my website. I\'m having following line of code from smarty template. I wan to call the jQuery AJAX function on the onclick of that h

1条回答
  •  独厮守ぢ
    2020-12-18 18:14

    Corrected Code:

    $(".edit_user_transaction_status").click(function(e) { 
             e.preventDefault();
             //for confirmation that status change
             var ans=confirm("Are you sure to change status?");
             if(!ans) {
                 return false;
             }  
             var post_url           = $(this).attr('href');
             var transaction_status_update = $('#transaction_status_update').val();      
    
             $.ajax({
                 type: "POST",
                 url: post_url+"&transaction_status_update="+transaction_status_update,
                     data:$('#transaction_form').serialize(),
                 dataType: 'json',  
                 success: function(data) {              
                     var error = data.login_error;
    
                     $(".ui-widget-content").dialog("close");
                    //This variables use for display title and success massage of transaction update              
                     var dialog_title   = data.title;              
                     var dialog_message = data.success_massage; 
                     //This get link where want to rerdirect
                     var redirect_link  = data.href;            
    
                     var $dialog = $("
    ") .html("

    "+dialog_message+"

    ") .dialog({ autoOpen: false, modal:true, title: dialog_title, width: 500, height: 80, close: function(){ document.location.href =redirect_link; } }); $dialog.dialog('open'); } }); });

    Note: Remove }); from the last line.

    0 讨论(0)
提交回复
热议问题