我正在尝试在Prestashop 1.6中创建和调用AJAX,并调用将保存所有ajax相关代码的ajax.php文件。我的jQuery函数包含$ .ajax({})是
function setCustomCarrierMethod(method_id){
if (method_id) {
$.ajax({
url: baseDir + '/modules/customcarrier/ajax.php',
type: 'POST',
data: 'ajax_function=set_customcarrier_method' + 'method_id=' + method_id,
dataType: 'json',
success: function(json) {
console.log("successfull request");
},
error: function(json) {
alert(json.error);
console.log("error in the request");
}
})
}
};
然后在ajax.php文件中我得到了:
<?php
session_start();
/* SSL Management */
$useSSL = true;
require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../config/smarty.config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');
include_once(dirname(__FILE__).'/customcarrier.php');
$customcarrier = new CustomCarrier();
if (Tools::getValue('ajax_function') == 'set_customcarrier_method') {
$customcarrier->setCustomCarrierMethod();
}
?>
任何想法我在这里遇到的错误都将受到高度赞赏!
答案 0 :(得分:0)
你必须使用&amp;在两个变量之间
data: 'ajax_function=set_customcarrier_method' & 'method_id=' + method_id
function setCustomCarrierMethod(method_id){
if (method_id) {
$.ajax({
url: baseDir + '/modules/customcarrier/ajax.php',
type: 'POST',
data: 'ajax_function=set_customcarrier_method' & 'method_id=' + method_id,
dataType: 'json',
success: function(json) {
console.log("successfull request");
},
error: function(json) {
alert(json.error);
console.log("error in the request");
}
});
}
}