我很新的JavaScript,所以我不知道我會怎麼做。但基本上我想在ajax data:
調用中添加for循環,而不是手動列出每個項目。每個Ajax數據
jQuery(document).ready(function()
{
var $payment = {
card: 'ajax-card',
month: 'ajax-month',
year: 'ajax-year',
cvv: 'ajax-cvv',
zip: 'ajax-zip',
phone: 'ajax-phone'
};
jQuery.each($payment, function($key, $val)
{
jQuery('.'+$val).attr({ id: $val });
});
jQuery('#pay-bill form input[type=submit]').click(function()
{
jQuery.ajax(
{
type: "POST",
url: "<?php echo get_bloginfo('template_directory').'/cnotethegr8/functions/braintree.php'; ?>",
dataType: "json",
data:
{
card: jQuery('#'+$card+' input').val(),
month: jQuery('#'+$month+' input').val(),
year: jQuery('#'+$year+' input').val(),
cvv: jQuery('#'+$cvv+' input').val(),
zip: jQuery('#'+$zip+' input').val(),
phone: jQuery('#'+$phone+' input').val()
},
success: function(data)
{
if (data)
{
alert(data.msg);
}
}
});
return false;
});
});
如果你想以JSON格式序列化的形式,看到這個[答案] [1] [1]:http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery – flynfish
如果你想以JSON格式序列化的形式,看到這個[答案] [ 1] [1]:http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery – flynfish