为什么我无法在以下场景中调用javascript AJAX函数?

时间:2013-09-13 07:43:52

标签: javascript php jquery ajax alert

来自smarty模板的我的代码片段如下:

<form name="transaction_form" id="transaction_form">
          <table class="trnsction_details" width="100%" cellpadding="5" >
            <tbody>    
              <tr>
                <td width="150"><b>Transaction Status : </b></td>
                <td class="view_details">
                <select name="transaction_status_update" id="transaction_status_update">   
                {if $transaction_status_array}
                  {foreach from=$transaction_status_array item="status"}
                  <option value="{$status}" {if $status == $user_transaction_details.transaction_status}selected="selected" {/if}>{$status|capitalize:true}</option>
                  {/foreach}
                {/if}
                </select>
              </td>       
              <td width="150">      
              </td>
            </tr>
        <tr>
     <td valign="top"><b>Remark : </b></td>
     <td><textarea name="transaction_remark" cols="30" rows="5"></textarea></td>
     <td><a class="edit_user_transaction_status" href="{$control_url}{$query_path}?op=edit_user_transaction&page={$page}&txn_no={$user_transaction_details.transaction_no}&transaction_data_assign={$user_transaction_details.transaction_data_assign}&user_id={$user_id}{if $user_name!=''}&user_name={$user_name}{/if}{if $user_email_id!=''}&user_email_id={$user_email_id}{/if}{if $user_group!=''}&user_group={$user_group}&{/if}{if $user_sub_group!=''}&user_sub_group={$user_sub_group}{/if}{if $from_date!=''}&from_date={$from_date}{/if}{if $to_date!=''}&to_date={$to_date}{/if}{if $transaction_status!=''}&transaction_status={$transaction_status}{/if}{if $transaction_no!=''}&transaction_no={$transaction_no}{/if}">Update</a></td>
     </tr>     
   </tbody>
 </table>
</form>

现在我想在点击锚标签时调用以下jQuery-AJAX函数,但我不能。我试图在函数的开头打印警报,但也没有打印。点击超链接可以帮我调用这个功能吗?提前谢谢。

$(document).ready(function() {
//This function is use for edit transaction status
    $(".edit_user_transaction_status").click(function(e) { alert("Hello");
         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 = $("<div class='ui-state-success'></div>")
                 .html("<p class='ui-state-error-success'>"+dialog_message+"</p>")
                 .dialog({
                     autoOpen: false,
                     modal:true,
                     title: dialog_title,
                     width: 500,
                     height: 80,
                     close: function(){                                     
                         document.location.href =redirect_link;
                     }                  
                 });                    

                 $dialog.dialog('open');                    
             }          
        });
     });
});

1 个答案:

答案 0 :(得分:1)

看起来您正在使用Smarty

您需要在

之间添加JavaScript
{literal}
    // your javascript or jquery code
{/literal}