WordPress.org

Ready to get started?Download WordPress

Forums

jquery $.post (7 posts)

  1. cuk
    Member
    Posted 12 months ago #

    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.

  2. Andrew
    Forum Moderator
    Posted 12 months ago #

    Are you receiving any JS errors?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 12 months ago #

  4. cuk
    Member
    Posted 12 months ago #

    @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...

  5. cuk
    Member
    Posted 12 months ago #

    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?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 11 months ago #

    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.wordpress.org/AJAX_in_Plugins

  7. cuk
    Member
    Posted 11 months ago #

    Hm, I read it and tried to alter the code, but it didn't work...
    Any further help would be greatly appreciated.

Reply

You must log in to post.

About this Topic

Tags