The code was utilizing require_once
and it wasn't executing, by removing these and debugging the problem was solved
Changed required to include_once so
include_once(dirname(__FILE__).'../../../../config/config.inc.php');
include_once(dirname(__FILE__).'../../../../init.php');
are working, but I still cannot access database files
old edit Ok so
`if (!defined('_PS_VERSION_'))
echo('no ps ');`
is echoing "no" into the return call of my ajax call, I have tried require_once(dirname(FILE).'../mymodule.php'); and it gave me a internal server error 500 in the console.
Every type of require_once call I've tried has given the same error, including direct hardcoded directories, url links, different files, files in the same directory, files in c and I've had no luck. older EDIT
Ok, $_GET is showing the data is correctly passed to the ajax, the require_once was not working, so the ajax.php was not executing at all.
However, now Tools::getValue is not working, I have not tried to edit the DB but I don't think it will work since Tools::getValue is causing an error
END OF EDIT
Here's my ajax call, where urlvariable is pointing to http://myserverladidah/ajax.php and there's a bunch of variables to go along with it ?data= (some data) &moreData= (some more data)
It's redirecting to the correct controller, so the page redirect is fine, but nothing is happening in the ajax.php, I've cut the ajax down to just writing a hard-coded statement to insert something into the database but there's nothing happening.
jQuery.get(urlvariable, function (data) {
window.location = 'index.php?controller=backendadminpage';
});
I've double checked the url that I'm calling, and all the variables are checking out, but I just can't get these javascript variables into the database.
Sorry it was insufficient information, I hope this helps // more information
var x = myFunction.getX;
var y = myFunction.getY;
var z = myFunction.getZ;
var urlvariable = '{$server}/modules/mymodule/ajax.php?x=' + x + '&y=' + y + '&z=' + z;
//ajax.php file
<?php
require_once('../myModule.php');
$sql = 'INSERT INTO `ps_my_table` (`name`) VALUES (`a`)';
Db::getInstance()->execute($sql);
//previously php file tried to get values using tools, but since nothing was happening I deleted the code and tried the above
ps_my_table (name
) VALUES (' . Tools::getValue['x'] .'
)';
//variables are dumping properly in javascript with
console.log(x);
console.log(y);
console.log(z);
//outputting
1
2
3
答案 0 :(得分:0)
代码正在使用require_once
并且它没有执行,通过删除这些并调试问题得到解决。
ajax脚本可以根据需要成功使用$ _GET来操作数据。