你找到这个页面了吗?
http://doc.prestashop.com/display/PS15/Using+jQuery+and+Ajax#UsingjQueryandAjax-MakingAjaxcallswithjQuery
我用它来开发我的模块。它还可以帮助您对使用 ajax 调用的其他模块进行大量使用(不记得哪些模块使用了)。
以下是如何进行 ajax 调用:
var query = $.ajax({
type: 'POST',
url: baseDir + 'modules/mymodule/ajax.php',
data: 'method=myMethod&id_data=' + $('#id_data').val(),
dataType: 'json',
success: function(json) {
// ....
}
});
然后,您只需要创建 PHP 文件。使用这种方式,不会加载 Prestashop 核心,因此如果要使用 Prestashop 功能,则必须手动执行:
// HTTP headers for no cache etc
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
要生成 JSON 输出,您可以使用:
die(Tools::jsonEncode($myArrays));
希望你得到你需要的东西。