【发布时间】:2014-11-18 21:15:49
【问题描述】:
我在付款方式的表单中有 2 个单选按钮 - 我想通过 ajax 在点击时加载模板部分。
现在我只能加载信用卡表格 - 我要做的是如果选择信用卡然后加载信用卡模板如果选择了贝宝然后加载贝宝模板部分。
表单元素
<input type="radio" class="radio-cc" name="method" value="creditcard"><span class="radio-span">Credit Card</span>
<input type="radio" class="radio-paypal" name="method" value="paypal"><span class="radio-span">Paypal</span>
jQuery
$("input[name=method]").change(function(){
$.ajax({
type: 'GET',
url: '<?php echo admin_url('admin-ajax.php');?>',
data: {
action: 'CCAjax'
},
success: function(textStatus){
$( '.default-form' ).append( textStatus );
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
});
PHP
function CCAjax()
{
get_template_part('cc');
die();
}
// creating Ajax call for WordPress
add_action('wp_ajax_nopriv_CCAjax', 'CCAjax');
add_action('wp_ajax_CCAjax', 'CCAjax');
【问题讨论】: