Zen Cart 用Jquery实现 Ajax调用
调用的 ajax.php 可以是catalog 根目录的ajax.php
也可以是后台的 ajax.php, 后台的ajax.php 会调用catalog 根目录的ajax.php并且传送当前位置
调用 ajax 必须传送url参数 act=xxxx 和 method = xxx
其中act 是class的名字
比如 act = “ajaxPayment”
那么就在 classes/ajax/zcAjaxPayment.php 作为配套class, ajaxPayment 首字符大写
调用一般写到 modules/pages/里jscript_main.php
var str = $('form[name="checkout_payment"]').serializeArray();
zcJS.ajax({
url: "ajax.php?act=ajaxPayment&method=prepareConfirmation",
data: str
}).done(function( response ) {
$('#checkoutPayment').hide();
$('#navBreadCrumb').html(response.breadCrumbHtml);
$('#checkoutPayment').before(response.confirmationHtml);
$(document).attr('title', response.pageTitle);
});
method 就对应class 里的function
class zcAjaxPayment extends base
{
/**
* Build replacement confirmation page, which doesn't transmit sensitive CHD
*/
public function prepareConfirmation() {
// 这是method 的内容
global $messageStack, $template, $breadcrumb, $template_dir_select, $template_dir, $language_page_directory, $currencies, $order, $zco_notifier, $db, $current_page_base, $order_total_modules, $credit_covers;
// error_reporting(E_ALL);
// ini_set('display_errors', 'on');
$_GET['main_page'] = $current_page_base = $current_page = FILENAME_CHECKOUT_CONFIRMATION;
}
}