当用户选择下拉选项时,Jquery不会更新我的PHP值 [英] Jquery is not updating my PHP value when user selects dropdown option

查看:79
本文介绍了当用户选择下拉选项时,Jquery不会更新我的PHP值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的购物车中的每件商品都有两个下拉菜单。



查看我的用户界面





当我选择我的两个选项时,成功的课程不会更新费用。它只在我刷新页面时更新,我不想刷新我的页面以获得费用。



我尝试过: < br $> b $ b

I got two dropdowns in each product in my cart.

look my UI


When i select my both option my class on success is not updating the cost. It only updates when i refresh the page, i dont want to refresh my page to get the cost.

What I have tried:

$(document).ready(function() {
  $('.fabric, .size').on('change', sendData);
  function sendData() {
  var id = $(this).data("id");
  var fabricID = $('.fabric[data-id=' + id +']').val(); 
  var sizeID   = $('.size[data-id=' + id +']').val();
    if ( fabricID !== "" && sizeID !== "") {
      $.ajax({
            type     : 'GET',
            url      : 'calculates.php',
            dataType : 'json',
            data     : {
                prod_id:id,
                fabric_id: fabricID,
                size_id: sizeID
            }
        }).done(function(data) {
            $('.cost' + id).text(data.val);
            $('.subtotal' + id).load(data.val);
         });
      }
  }
});





这是我在用户尝试更新的地方选择他的产品选项





this is where i am trying to update when user select his product options

'.$value.' R$: '.$_SESSION['icms'.$id].' R$: '.$value * $_SESSION['icms'.$id] .'>

My $value holds the quantity of my product. And other problem that i'm getting is when i click in my plus and remove button,i don't get my subtotal to updated either.

And this script handles my $value to keep updating when i click on my button.

<pre lang="JavaScript">$('.actions').click(function(e){
  e.preventDefault();
  var action = $(this).attr('data-action'); 
  var id = $(this).attr('product_id');
  var cost_id = $(this).data("id");
  console.log("triggered action " + action + " for product " + id); //debugging
  $.ajax({
    url: 'cart_functions.php',
    type : 'GET',
    data: {action:action,prod_id:id},
    dataType: 'json',
    success: function(data)
    {
      console.log("ajax call returned the following: " + JSON.stringify(data)); //debugging
      if (data.result == "success") {
        if (action == "plus" || action == "remove")
        {
          console.log("identified product td for " + id + ": " + $(".product" + id).length); //debugging
          $(".product" + id).text(data.val);
          $(".subtotal" + cost_id).text(data.val);
          //update the UI with the new total
        }



因此,您可以看到我在两个脚本中使用了我的类小计。因此,当我点击我的加号或删除按钮时,它可以更新,而下拉选项会更改每个产品的小计和成本。为什么我的jquery没有更新我的成本和小计?

我仍​​然是jquery的菜鸟。请帮忙。


So as you can see i used in both scripts my class subtotal. So it can update when i click in my plus or remove button and on dropdown selection changes the subtotal and the cost for each product. Why my jquery is not updating my cost and subtotal?
Im still a noob at jquery. Please some help.

推荐答案

document )。ready( function (){
(document).ready(function() {


' .fabric ,. size')。on(' change',sendData);
< span class =code-keyword> function sendData(){
var id =
('.fabric, .size').on('change', sendData); function sendData() { var id =


this )。data( id);
var fabricID =
(this).data("id"); var fabricID =


这篇关于当用户选择下拉选项时,Jquery不会更新我的PHP值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆