JavaScript How to show message in view & replace a div using ajax in codeigniter? show message in view mvc,show message in view laravel,

I am stuck with ajax... I have a cart and it has gift vouchers, i) the code checks for valid voucher and if its not valid then it should show message "invalid voucher". ii) If voucher if valid and is set in db,then change the cart total using gift amount.

So I have set the message , but i dont know how to dislay it.And Using gift i have stored the new cart total ie gift_cart_total.In db, i have fields for cart_total,voucher , gift_cart_total.How can i remove my original cart div and show new div using gift_cart_total.

View:

<div class="giftvoucher">
   <input type="text" name="gift_voucher_number" id="gift_voucher_number" placeholder="Voucher Number" value="" size=18>
   <input type="text" name="gift_voucher_pin" id="gift_voucher_pin" placeholder="Voucher Pin" value=""size=18>
   <input type="button" value="Apply" onclick="checkGiftVoucher()" id="apply_button">
</div>
<script type="text/javascript">
function checkGiftVoucher(){
    var gift_voucher_number = $("#gift_voucher_number").val();
    var gift_voucher_pin = $("#gift_voucher_pin").val();

    $.ajax({
         type: "POST",
         url: "<?php echo base_url('cart/giftvalidate'); ?>",
         data: {gift_voucher_number:gift_voucher_number,gift_voucher_pin:gift_voucher_pin} , 

          success: function(data){
             return false;

         },
        });
  }

   </script> 

Controller:

public function giftvalidate(){
    if(isset($_POST['gift_voucher_number']) && $_POST['gift_voucher_number'] != '' && isset($_POST['gift_voucher_pin']) && $_POST['gift_voucher_pin'] != ''){           
        $app21_url      = APP21_URL;
        $country_code   = COUNTRY_CODE;

        $gift_voucher_number    = $_POST['gift_voucher_number'];
        $gift_voucher_pin   = $_POST['gift_voucher_pin'];

        $result         = $this->cart_model->checkValidGift($gift_voucher_number, $gift_voucher_pin, $app21_url, $country_code);
        if($result['databool'] && !empty($result['dataValue'])){

            $discount   = $result['dataValue']['AvailableAmount'];
        }else{

            $gift_flash = $result['datamsg'];
        }

    }elseif(isset($_POST['gift_voucher_number']) && (empty($_POST['gift_voucher_pin']) || $_POST['gift_voucher_pin'] =='')){            
        $result['datamsg']  = "Please enter the gift voucher pin";  
    }

    echo json_encode($result);
}

Model :

function checkValidGift($gift, $gift_pin, $app21_url, $country_code){

    $returndata = array();
    $dataValue  = array();
    $datamsg    = '';
    $databool   = false;
    $cartTotal  = $this->getTotalCart();
    $GVValid_url = some url here;

    $headers = array(
        "GET HTTP/1.1",
        "Content-type: text/xml",
        "Accept: Version_2.0"
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $GVValid_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 900);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

    $data = curl_exec($ch);

    if (curl_errno($ch)) {

        $result = 'cURL ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);


        $databool = false;
        $datamsg  = 'Gift Voucher & pin are not Valid';

    }else if($gift='100038' && $gift_pin='7655'){
        $gift='100038';
        $AvailableAmount = '200';

        if ($AvailableAmount > $cartTotal) {
            $gift_cart_total = $cartTotal;
        }else{
            $gift_cart_total = $cartTotal-$AvailableAmount;
        }


        if(!$this->session->userdata('s_uid') || $this->session->userdata('s_uid')==''){
            $user_type = 'Guest';
            $user_id   = $this->session->userdata('__ci_last_regenerate');
        }else{
            $user_type = 'Member';
            $user_id = $this->session->userdata('s_uid');
        }

        $insertData = array(
                            'user_id'   => $user_id,
                            'gift_id'   => $gift,
                            'pin'       => $gift_pin,
                            'gift_amount'    => $AvailableAmount,
                            'gift_cart_total' =>$gift_cart_total
                        );

        $table      = 'cart_mast';
        $sql        = "SELECT * FROM $table WHERE user_id = '{$user_id}'";

        $query      = $this->db->query($sql);


        if($query->num_rows() != 0){
            $carts = $query->result_array();
            foreach ($carts as $row) {
                $this->db->where('user_id', $user_id);
                $this->db->update($table, $insertData);
                //echo $this->db->last_query(); exit;
            }
        }else{
            $this->db->insert($table, $insertData);
        }

        $dataValue = array(
                            'giftId'          => $gift,
                            'AvailableAmount' => $AvailableAmount,
                            'gift_cart_total' => $gift_cart_total
                       );

        $databool = true;
        $datamsg  = '';
    }
 else{

        $xml = new SimpleXMLElement($data);

        if(count($xml) <= 2 && !empty($xml->ErrorCode)){

            $databool = false;
            $datamsg  = 'The voucher has expired';

        }else{

            $VoucherNumber   = (int)($xml->VoucherNumber);
            $gift_pin        = $pin;
            $ExpiryDate      = (int)($xml->ExpiryDate);
            $AvailableAmount = (int)($xml->AvailableAmount);

            $AvailableAmount = number_format($AvailableAmount, 2);
            $user_id    = $this->session->userdata('session_id');

            $table      = 'gift_voucher';
            $sql        = "SELECT * FROM $table WHERE user_id = '{$user_id}'";
            $query      = $this->db->query($sql);
            $insertData = array(
                                'user_id'   => $user_id,
                                'gift_id'   => $VoucherNumber,
                                'pin'       => $gift_pin,
                                'amount'    => $AvailableAmount
                            );

            if($query->num_rows() != 0){

                $carts = $query->result_array();

                foreach ($carts as $row) {
                    $this->db->delete($table, array('user_id' => $user_id)); 
                    $this->db->insert($table, $insertData);
                }

            }else{
                $this->db->insert($table, $insertData);
            }

            $giftId = $this->db->insert_id();


            $dataValue = array(
                                'giftId'          => $giftId,
                                'VoucherNumber'   => (!empty($ss_id))? $ss_id:$VoucherNumber,
                                'AvailableAmount' => $AvailableAmount
                           );

            $databool = true;
            $datamsg  = '';

        }

    }

    curl_close($ch);

    $returndata['databool']   = $databool;
    $returndata['datamsg']    = $datamsg;
    $returndata['dataValue']  = $dataValue;

    return $returndata;
}
Answer:1

JS models concurrency by an event loop. As a result there are no race conditions. So what are the drawbacks of the following type safe operation in the main scope of a program that would justify any ...

JS models concurrency by an event loop. As a result there are no race conditions. So what are the drawbacks of the following type safe operation in the main scope of a program that would justify any ...

  1. what is the typical class size at texas a&m
  2. what is the typical class size for ucla
  3. what is the typical class size at stanford university
  4. what is the typical class size at usc
  5. what are a typical class of anticancer drugs
  6. what is the typical class size at nyu
  7. what is the typical class size at texas tech
  8. what is the typical class size at asu
  9. what is the typical class size at unc
  10. what is the typical class size at gcu
  11. what is the typical class size at osu
  12. what is the typical class size at gsu
  13. what is the typical class size at pvamu
  14. what is the typical class size at wssu
  15. what is the typical class size at ttu
  16. what is the typical class size at csumb
  17. what is the typical class size at uc merced
  18. what is the typical class size at vsu
  19. what is the typical class size at apsu
  20. what is the typical class size at unr

I need to add class to input parent if input is not empty or focus because I want to change label position. <div class="input-field"> <input type="email" name="email" ng-model="email" ...

I need to add class to input parent if input is not empty or focus because I want to change label position. <div class="input-field"> <input type="email" name="email" ng-model="email" ...

I am trying to change custom icon of video, when video is toggled(Play/Pause). ngAfterViewInit() { const vdoCont = document.querySelector('.video-player'); const vdo = vdoCont.querySelector('video')...

I am trying to change custom icon of video, when video is toggled(Play/Pause). ngAfterViewInit() { const vdoCont = document.querySelector('.video-player'); const vdo = vdoCont.querySelector('video')...

  1. javascript snake
  2. javascript foreach
  3. javascript map
  4. javascript for loop
  5. javascript array
  6. javascript substring
  7. javascript switch
  8. javascript reduce
  9. javascript date
  10. javascript regex
  11. javascript filter
  12. javascript string contains
  13. javascript function
  14. javascript replace
  15. javascript slice
  16. javascript split
  17. javascript settimeout
  18. javascript download
  19. javascript interview questions
  20. javascript promise

I'm trying to implement an image preview. It works fine until i came to a problem where i need to prevent the input file to not change. JSFIDDLE When trying to change to image its fine. After ...

I'm trying to implement an image preview. It works fine until i came to a problem where i need to prevent the input file to not change. JSFIDDLE When trying to change to image its fine. After ...

  1. jquery preventdefault return false
  2. preventdefault jquery return
  3. jquery preventdefault vs return false
  4. jquery event.preventdefault vs return false
  5. jquery event.preventdefault return false