0
我是這個Ajax的新手。WooCommerce追蹤訂單提交AJAX
我想要做的是提交訂單跟蹤表格&用AJAX顯示結果。所以,我想阿賈克斯顯示DIV track_result
結果的問題是下面的代碼工作正常,但跟蹤結果顯示爲整個新頁面(與頭,容器&頁腳)DIV track_result內。
我無法弄清楚只在div中顯示結果(WooCommerce類)而不是整個新頁面。
這裏是WooCommerce形式,tracking.php
<form action="<?php echo esc_url(get_permalink($post->ID)); ?>" method="post" class="track_order">
<p><?php _e('To track your order please enter your Order ID in the box below and press the "Track" button. This was given to you on your receipt and in the confirmation email you should have received.', 'woocommerce'); ?></p>
<p class="form-row form-row-first"><label for="orderid"><?php _e('Order ID', 'woocommerce'); ?></label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php esc_attr_e('Found in your order confirmation email.', 'woocommerce'); ?>" /></p>
<p class="form-row form-row-last"><label for="order_email"><?php _e('Billing Email', 'woocommerce'); ?></label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php esc_attr_e('Email you used during checkout.', 'woocommerce'); ?>" /></p>
<div class="clear"></div>
<p class="form-row"><input type="submit" class="button" name="track" value="<?php esc_attr_e('Track', 'woocommerce'); ?>" /></p>
<?php wp_nonce_field('woocommerce-order_tracking'); ?>
jQuery的
$('.track_order').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('.track-results').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
對不起,我不明白,我是外行,還要感謝您的幫助! –
你只需要加載沒有頁眉和頁腳的必需的視圖...爲此,當進行Ajax調用時已經傳遞了1個變量...如果變量us 1他們不加載頁眉r頁腳... –
它仍然會顯示頁眉和頁腳以外的頁面上的其他內容,我只想顯示類woocommerce&沒有別的 –