WordPress.org

Forums

jquery $.post (7 posts)

  1. cuk
    Member
    Posted 1 year 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
    Nuh uh moderator
    Posted 1 year ago #

    Are you receiving any JS errors?

  3. cuk
    Member
    Posted 1 year 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...

  4. cuk
    Member
    Posted 1 year 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?

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

  6. cuk
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags