如何在javascript中获取foreach输入值并将其传递给ajax数据?

This is my Form

<form method="post" id="BargainForm">
    <input type="hidden" name="pro_id" class="pro_id" id="pro_id" value="<?php echo $pro_id; ?>">
    <input type="hidden" name="customer_id" class="customer_id" id="customer_id" value="<?php echo $customer_id; ?>">
    <input type="text" name="bargain_qty" class="bargain_qty" id="bargain_qty" placeholder="Qty" required/></br></br>
    <?php if($productType = 'Configurable'): ?>
        <?php foreach($attributes as $attribute): ?>
            <input type="text" name="<?php echo strtolower($attribute['store_label']); ?>" 
                                        class="<?php echo strtolower($attribute['store_label']); ?>" 
                                        id="<?php echo strtolower($attribute['store_label']); ?>" 
                                        placeholder="<?php echo $attribute['store_label'] ?>"></br></br>
        <?php endforeach; ?>
    <?php else: ?>

    <?php endif; ?>
    <input type="text" name="bargain_price" class="bargain_price" id="bargain_price" placeholder="Total Price" required/></br></br>
    <input type="submit" name="bargain_btn" class="bargain_btn">
</form>

Here is my javascript code

<script type="text/javascript">
$(function () {
    $('.bargain_btn').click(function(e) {
        var qty = $( "#bargain_qty" ).val();
        var price = $( "#bargain_price" ).val();
        var pro_id = $( "#pro_id" ).val();
        var customer_id = $( "#customer_id" ).val();
        var att_lable = $( "#<?php echo strtolower($attribute['store_label']); ?>" ).val();
        alert(att_lable);
        e.preventDefault();
        $.ajax({
            url: "<?php echo Mage::getUrl('bargain/Ajax/index'); ?>",
            type: "POST",
            data: {qty,price,pro_id,customer_id},
            success: function(data) {
                if(data.success) {
                }
            }
        });
    });
});

In form i am using foreach. If i have 2 data so it will display 2 input tags, i just don't know how to save values of that 2 input and pass it to data: {qty,price,pro_id,customer_id},

Thank you in advance!

查看全部
double820122
double820122
2016/12/12 07:13
  • php
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复