這是我的表如何在JavaScript中獲取foreach輸入值並將其傳遞給ajax數據?
<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>
這裏是我的javascript代碼
<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) {
}
}
});
});
});
在我使用的foreach形式。如果我有2個數據,所以它會顯示2個輸入標籤,我只是不知道如何保存該2個輸入的值並將其傳遞到data: {qty,price,pro_id,customer_id},
先謝謝您!
謝謝它的工作。@ Mayank – Vky
這是偉大的。接受答案,如果它適合你:) –
是的隊友,但你知道我們不能接受即時。有時間限制 – Vky