Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:20:59+00:00 2026-06-08T10:20:59+00:00

I would really need some help from to AJAX Guru master overthere to help

  • 0

I would really need some help from to AJAX Guru master overthere to help me building my update cart function on my website in AJAX.

So basically, what I would like to do is, when I modify one of my product in one input_dropdown, my ‘update_cart’ function is automaticaly called and my prices are updated as well as my input

EDIT : I rewrite my question since I made some progress thanks to Matei

Here is my view :

<?php 
          $options = array(
             '0'  => '0',
             '1'  => '1',
             '2'  => '2',
             '3'  => '3',
             '4'  => '4',
             '5'  => '5',
             '6'  => '6',
             '7'  => '7',
           );

       if($product['quantity']==0){
        $value[$product['title']] = set_value('quantity'.$product['title']);
       }else{
        $value[$product['title']] = $product['quantity'];
       }
       $data0 = 'class="quantSelect" value="'.$value[$product['title']].'" id="quant'.$product['title'].'"';

       echo  form_dropdown('quantity'.$product['title'], $options, $value[$product['title']],$data0);
     ?&gt;
    </td>
    <td>
     &lt;?php echo $product['price'] ?&gt;
    </td>
    <td id="&lt;?php echo 'price'.$product['title']?&gt;">
     $&lt;?php echo $total[$product['title']] ?&gt;
    </td>[/code]

Well, everything is in a foreach loop but I think that here, it doesn’t matter.

Then I tried to set up the Matei AJAX function :

$(".quantSelect").click(function(){  
    $.POST("&lt;?php echo base_url().'main/update_cart';?&gt;",  
           {product_id:$('&lt;?php echo $product['quantity']; ?&gt;').val(),quantity:$('&lt;?php echo 'quantity'.$product['title'] ?&gt;').val()},  
           function(data){  
                if(data.success) {  
                     $("&lt;?php echo 'price'.$product['title']?&gt;").val(data.some_returned_value); // update value of an text input or textarea (view more info about jQuery selectors)
                     $("#totalPriceWithTaxes").html(data.some_other_returned_value); // update value of a paragraph                    
                }
           }, 'json');
});

And at last the update cart function :

function  update_cart(){
 $success = false;
  if(!empty($_POST['product_id']) && !empty($_POST['quantity']) && is_numeric($_POST['quantity'])) {  

   // I get all the information i need here in order to calcul the final price
   //We calcul the final price with taxes, shipping and everything.
   $data['totalPriceWithTaxes'] = $data['tax'] + $data['totalPrice'] + $data['Shipping']->shipping;
   $this->session->set_userdata('totalPriceWithTaxes', $data ['totalPriceWithTaxes']);

   $success = true;
   $some_returned_value = 69;
   $some_other_returned_value = $data['totalPriceWithTaxes']; // the final price
  }
 echo json_encode(array("success" => $success, 
      "some_returned_value" => $some_returned_value,
      "some_other_returned_value" => $some_other_returned_value));

 }

Here we are, so I can’t see any update. If someone could help me to figure out how to set up that AJAX Function, I would deeply appreciate 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:21:00+00:00Added an answer on June 8, 2026 at 10:21 am

    I recommend you to take a look at jQuery.post() method of jQuery library.

    Let’s see the following example:

    Javascript code:

    $("#submit-button").click(function(){  
        $.POST("/PATH_TO/update_cart.php",  
               {product_id:$('#product-id').val(),quantity:$('#quntity').val()},  
               function(data){  
                    if(data.success) {  
                         $("#form-field-id").val(data.some_returned_value); // update value of an text input or textarea (view more info about jQuery selectors)
                         $("p#form-p-id").html(data.some_other_returned_value); // update value of a paragraph                    
                    }
               }, 'json');
    });
    

    For more info about jQuery Selectors please check this

    PHP code:

    <?php
         $success = false;
         if(loged()) { // verify if the user is loged (if it's needed)
             if(!empty($_POST['product_id']) && is_numeric($_POST['product_id']) && !empty($_POST['quantity']) && is_numeric($_POST['quantity'])) {  
                 // use here your additional code
                 // update database
                 // if every condition is applied then confirm that the fields are updated
                 $success = true;
                 $some_returned_value = "data has been successfully updated";
                 $some_other_returned_value = 45.3; // the final price
             }
         }
         echo json_encode(array("success" => $success, 
                                "some_returned_value" => $some_returned_value,
                                "some_other_returned_value" => $some_other_returned_value));
    ?>
    

    This is a simple example about how you can use jQuery POST method and PHP for updating data you want. I didn’t use any of your code, but you can try to update your cart like this. jQuery is a powerfull library, so I’ll recommend you to take a look at it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need some help with a background on a website. You can see
I would really appreciate any help with the following problem: I need to be
I would really appreciate it if some of you could help optimize my tables,
I need some help from some linux gurus. I am working on a webapp
I'm not really good at Javascript/jQuery yet, so I need some help. I have
I would really appreciate some help. I spent almost the whole morning on it.
guys i really REALLY need some help on this one. 2 days i've been
I'm at a lose end and would really appreciate some help as it is
I've some questions .. and I really need your help. I have an application.
OK Ladies and Gents, I would really appreciate some help: This is my table:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.