你找到这个网页? 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));
希望你得到你需要的东西。