0

I want to post the fields price and plateId to a database table without using any form, when the user clicks the Order button. Would it be possible? Otherwise, could you suggest an other solution?

<div class="menu">
  <img src="/images/wings.png" />
  <div>
    <span id="price">Price:$40.00</span>
    <div class="description">
      <span id="plateId">HOT WINGS</span>
    </div>
  </div>
  <button id="btn">Order</button>
</div>

<div class="menu">
  <img src="/images/chicken.png" />
  <div>
    <span id="price">Price:$70.00</span>
    <div class="description">
      <span>Cooked Chicken</span>
    </div>
  </div>
  <button id="btn">Order</button>
</div>

2 Answers 2

1

You need to call AJAX first and in your case you should collect information about plateId and price and return the data to AJAX so it can store in your database.

   $('#btn').click(function () {
     var orderInformation = {
       var price = $(#price).text();
       var plateId = $(#plateId).text();
     };

     $.ajax({
       type: 'POST',
       url: 'post-information-in-your-db.php',
       dataType: "json",
       data:(orderInformation),
       success: function (data) {
         alert(data);
       }
     }); 
   });

It is also possible to treat the data returned from the variable and different display shapes after success.

Sign up to request clarification or add additional context in comments.

Comments

1

you can make a server call through ajax by calling a javascript function as:

 function send_value() {
   $.ajax({
     type: 'POST',
     url: 'get.php',
     dataType: "json",
     data:({"uniId":"test"}),
     success: function (data) {
     console.log(data);
     } 
  });
  return false;
  }

Pass data as an argument and put them as json in data:({"uniId":"test"})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.