• Hi!

    I’m trying to post some data from the template php to another php which I added to wordpress files.
    This is a part of the code:
    $.post('drugi.php', {name:tralala}, function (data){...}
    It seems it doesn’t send anything to drugi.php at all. Is this first attribute wrong? Should i write the whole URL?

    Please help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Are you receiving any JS errors?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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('https://sklopnjak.uni.me/wp-content/themes/twentyeleven-dijete/trazilica_jedan.php', {znamen:znamen},function (data){
    			$('#save_status').text(data);
    			 });

    Some ideas?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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:
    https://codex.www.ads-software.com/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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘jquery $.post’ is closed to new replies.