嗨,当用户到达订单确认页面时,我试图将一些数据保存到数据库中新创建的表中,而我被卡住了。我知道AJAX调用正在与php文件进行通信,因为我可以简单地用console.log记录response(output),然后从php文件中得到期望的结果(即:echo'hello')-所以在这里一切都很好。
我还在init.php中注册了新的表别名。
这是来自order_message.tpl文件的JS代码:
var newData = {
"one":"test one",
"two":"test two"
};
$.ajax({ url: '/newDir/newFile.php',
data: {
dataToSend: newData
},
type: 'post',
success: function(output){
console.log(output);
},
error: function(xhr, textStatus, error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
这是来自文件root / newDir / newFile.php的PHP代码:
require '../init.php';
require '../include/func/func.db.php';
if(isset($_POST['dataToSend']) && !empty($_POST['dataToSend'])) {
$ssData = json_decode($_POST['dataToSend']);
myFunc($ssData);
} else {
die( header('Location: ../404.html') );
}
function myFunc($dt){
$toSaveData = array(
'one' => $dt->one,
'two' => $dt->two
);
func_array2insert ('my_new_table', $toSaveData);
}
我可以看到在开发工具中进行了AJAX调用,但是它输出了以下错误:
GET https://localhost/site/newDir/index.php 404(未找到)
未找到
错误
未找到
我没有在此路径的代码中引用任何位置-该地址不存在-https://localhost/site/newDir/index.php,所以我不确定这里发生了什么。接下来的3个错误来自AJAX错误方法。并且在数据库中没有数据被存储。
如果我注释掉“ require'../init.php';”我没有收到任何错误,但是得到了很长的html代码字符串。但是仍然没有数据保存到数据库中。
任何人都可以看到问题所在吗?
非常感谢。
最佳答案
1)将newFile.php脚本移动到库存cart.php脚本所在的文件夹中。
2)将补丁应用到PHP文件
--- old.php 2019-03-14 15:19:10.162222071 +0400
+++ new.php 2019-03-14 15:25:41.160826722 +0400
@@ -1,5 +1,11 @@
-require '../init.php';
-require '../include/func/func.db.php';
+require __DIR__.'/top.inc.php';
+
+define('QUICK_START', true);
+define('SKIP_CHECK_REQUIREMENTS.PHP', true);
+define('USE_SIMPLE_SESSION_INTERFACE', true);
+define('USE_SIMPLE_DB_INTERFACE', true);
+
+require __DIR__.'/init.php';
if(isset($_POST['dataToSend']) && !empty($_POST['dataToSend'])) {
$ssData = json_decode($_POST['dataToSend']);
或在此处https://bt.x-cart.com/view.php?id=50556#attachments下载新版本
3)更改行中的URL
$.ajax({ url: '/newDir/newFile.php',
到新的。使用相对或绝对路径。
关于php - X-Cart 4.6将数据提交到db中的新表时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55143366/