2013-09-17 06:21

如何在以下场景中的“jQuery ajax()方法”中显示Colorbox弹出窗口?

  • php
  • ajax
  • javascript
  • jquery

I'm using PHP, Smarty, jQuery, AJAX, Colorbox - a jQuery lightbox, etc. for my website. There is some old code done using jQuery AJAX method to display the message in popup using standard jQuery library functions. Now I want to replace that typical popup using Colorbox popup. In short Iwant to change the design part only the message part is as it is. I tried to do this but couldn't succeeded yet. Can you help me in doing the necessary changes to the existing old code in order to show the messages in Colorbox popup instead of typical popup? For your reference I'm putting the old code below:

Code from smarty template to give a call to the jQuery AJAX function is as follows:

<span class="submit edit_user_transaction_status" value="{$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</span>

The code from js file which contains the existing AJAX code is as follows:

$(document).ready(function() {

//This function is use for edit transaction status
    $(document).on('click', '.edit_user_transaction_status', function (e) {



         //for confirmation that status change
        var ans=confirm("Are you sure to change status?");
        if(!ans) {
          return false;

        var post_url           = $(this).attr('value');
        var transaction_status_update = $('#transaction_status_update').val();       

          type: "POST",
          url: post_url+"&transaction_status_update="+transaction_status_update,
          dataType: 'json',  
          success: function(data) {             
            var error = data.login_error;

            //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>")
                            autoOpen: false,
                            title: dialog_title,
                            width: 500,
                            height: 80,
            close:  function(){                                     
              document.location.href =redirect_link;

Now the code snippet from PHP file which contains the PHP code and success message is as follows:

case "edit_user_transaction":

                $transaction_no            = $request['txn_no'];
                $transaction_status_update = $request['transaction_status_update'];
                $transaction_data_assign   = $request['transaction_data_assign'];
                $user_id                   = $request['user_id'];
                $from_date                 = $request['from_date'];
                $to_date                   = $request['to_date'];
                $page                      = $request['page'];

                    $query = "&transaction_no=".$request['transaction_no'];
                // If public transaction status is entered
                if($request['transaction_status']!='') {
                    $query .= "&transaction_status=".$request['transaction_status'];

                // For checking transaction no is empty, blank, and numeric
                if($transaction_no!='' && !empty($transaction_no)) {
                    $objUserTransactions  = new UserTransactions();
                    $objUserPackages      = new UserPackages();

                    //if transaction status update to success and transaction data not yet assign
                    if(empty($transaction_data_assign) && $transaction_data_assign == 0 && $transaction_status_update == "success") {
                        $user_transactions = $objUserTransactions->GetUserTransactionsDetailsByTransactionNo($transaction_no, $user_id);

                        $i = 0 ;
                        $j = 0 ;
                        //Create array related study and test
                        foreach($user_transactions['transaction_details'] as $my_cart) {
                            if(!empty($my_cart['pack_id'])) {
                                if($my_cart['pack_type'] == 'study') {
                                    $data['study'][$i] = $my_cart['pack_id'];
                                if($my_cart['pack_type'] == 'test') {
                                    $data['test'][$j]['pack_id']          = $my_cart['pack_id'];
                                    $data['test'][$j]['pack_expiry_date'] = $my_cart['pack_expiry_date'];
                                    $data['test_pack_ids'][$j]            = $my_cart['pack_id'];

                        if(!empty($data['study'])) {
                            $objUserStudyPackage = new UserStudyPackages();
                            //Update packages sold count & purchase date in package table

                            //For insert packages related data to package_user table
                            foreach($data['study'] as $study_pack_id) {
                                $objUserPackages->InsertStudyPackagesToPackageUser($study_pack_id, $user_id);


                        if(!empty($data['test'])) {
                            $objUserTestPackage  = new UserTestPackages();
                            //Update packages sold count & purchase date in test package table

                            //For insert test related data to test_user table
                            foreach($data['test'] as $test_pack_data) {
                                $objUserPackages->InsertTestPackagesToTestUser($test_pack_data['pack_id'], $test_pack_data['pack_expiry_date'], $user_id);

                        //This function is use for update status inprocess to success and transaction_data_assign flag 1
                        $user_transactions = $objUserTransactions->UpdateTransactionStatusByTransactionNo($transaction_no, $user_id, $transaction_status_update, '1');

                    } else {
                        // This function is use for update status
                        $user_transaction_details = $obj_user_transactions->UpdateTransactionStatusByTransactionNo($transaction_no, $user_id, $transaction_status_update);

                    //Email functionality when status update                

                    **$reponse_data['success_massage'] = "Transaction status updated successfully";
                    $reponse_data['title']           = "Transaction";
                    $reponse_data['href']            = "view_transactions.php?page=".$page."&from_date=".$from_date."&to_date=".$to_date.$query;                                
                    $reponse_data['login_error']     = 'no';
                    $reponse_data = json_encode($reponse_data);

                    echo $reponse_data;



The code shown in bold font is the success response message. Can you help me in this regard, please? Thanks in advance.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享