doxzrb8721 2013-09-17 06:21
浏览 56
已采纳

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

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) {

      e.preventDefault();

      $.colorbox.close();

         //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();       

        $.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');                   
             }          
        });
     });
});

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'];

                if($request['transaction_no']!=''){
                    $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'];
                                    $i++;
                                }
                                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'];
                                    $j++;
                                }
                            }
                        }

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


                            //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
                            $objUserTestPackage->UpdateTestPackagePurchaseData($data['test_pack_ids']);

                            //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                
                    include_once("transaction_status_update_email.php");                    

                    **$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;

                    die();**
                }

                break;

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

  • 写回答

1条回答 默认 最新

  • dongpai9986 2013-09-17 07:14
    关注

    Yo, you asked for help in PHP chat. Hopefully this helps:

    So the dialog portion at the bottom needs to change to support colorbox. Firstly, load all your colorbox stuff. Second, you'll need to create your colorbox content dynamically by either grabbing content from an element on the page or building it on the fly.

    You might need to debug some of this but here's generally how you do this...

    Delete the entire $dialog variable

    var $dialog = .....
    

    And change that to something that will look similar to:

    var $dialog = $('<div>').addClass('ui-state-success').append($('<p>').addClass('ui-state-error-success').html(dialog_message));
    

    Then you'll need to do something like this:

    $.colorbox({html: $dialog});
    

    If you're having trouble seeing the content that is dynamically built inside your colorbox try calling $.colorbox.resize() on the opened callback:

    opened: function(){
      $.colorbox.resize();
    }
    

    If that doesn't work you may also need to pass a innerWidth/innerHeight or width/height property inside the resize method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏