ボタンクリックでjsonデータを生成する必要がありますが
、ショッピングカートのデモリンク
http://jsfiddle.net/bkw5p/48/でjsonを取得できません。
2231 次
1 に答える
1
HTMLの最後、との<p class="total">
間<h2>
:
<input type="submit" id="submit" value="Make an order" />
JS内$(function() { ... })
::
$('#submit').bind('click',function(){
if (!$('table#cartcontent1 tr').length) {
alert('You have no Items in Your Cart');
} else {
var result = new Array();
var name, qty, price;
$('table#cartcontent1 tr').each(function(){
name = $(this).find('td[data-bind="text:name"]').text();
qty = $(this).find('input[data-bind="value:qty"]').val();
price = $(this).find('td[data-bind="text:price"]').text();
result.push( {'name' : name, 'qty' : qty, 'price' : price } );
})
$.ajax({
type:"POST",
url: 'ordering.php',
data: {data: result},
success: function(msg){
// do something when success
}
});
}
return false;
})
PHPでは、次のようになります。
$data = $_POST['data'];
foreach ($data as $val) {
echo $val['name']; // Feeling
echo $val['price']; // 25
echo $val['qty']; // 3
}
于 2012-07-30T08:36:57.393 に答える