Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Are you receiving any JS errors?
Thread Starter
cuk
(@cuk)
@andrew, nope. No errors. I fixed the URL problem, still it seems drugi.php doesn’t even get activated.
@samuel, wrappers didn’t solve the problem.
Sorry, now it does output some error, but the error’s about wpdb insert. I don’t know what made it change…
Thread Starter
cuk
(@cuk)
I’m getting this:
Fatal error: Call to a member function insert() on a non-object in /home/a2865846/public_html/wp-content/themes/twentyeleven-dijete/trazilica_jedan.php on line 4
This is the whole code from trazilica_jedan.php
<?php
if (isset($_POST['znamen'])){
$lepo = $_POST['znamen'];
$update = $wpdb->insert('users', array('user_id' => 12, 'uporabniki' => 'trajj'),array("%d", "%s"));
echo "$update";
}
else {
echo "napaka! :(";
}
?>
It is activated from the template file trazilica_dva.php. This is the part:
$.post('http://sklopnjak.uni.me/wp-content/themes/twentyeleven-dijete/trazilica_jedan.php', {znamen:znamen},function (data){
$('#save_status').text(data);
});
Some ideas?
You’re calling a PHP file in the theme directly and then attempting to use the $wpdb object, but because you called the file directly, WordPress isn’t loaded, and $wpdb is undefined.
You need to learn to use AJAX calls correctly in WordPress:
http://codex.ww.wp.xz.cn/AJAX_in_Plugins
Thread Starter
cuk
(@cuk)
Hm, I read it and tried to alter the code, but it didn’t work…
Any further help would be greatly appreciated.