WordPress.org

Ready to get started?Download WordPress

Forums

The proper way to have Javascript call PHP scripts (2 posts)

  1. fatalx
    Member
    Posted 3 years ago #

    Hello,

    I am currently working on a project that requires users to down vote and upvote things, an example being links in a post.

    I have all of the voting data saved into custom fields for each post.
    Currently when a person down votes or upvotes something I have a Javascript function that makes a xmlhttprequest to a PHP script somewhere on my server.

    The script loads wordpress functions using
    require_once('../../../../wp-load.php');

    and I update_post_meta or do whatever I have to do.

    I am wondering if this is the best way to go about getting this effect and what is the best practice for doing something like this?

    Thanks

  2. Reuben Gunday
    Member
    Posted 3 years ago #

    Surely, that's not the best way to use Ajax.

    Check this http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Viewer-Facing_Side to learn how to use ajax on front end. Though it uses plugins as examples, you can try it with themes.

Topic Closed

This topic has been closed to new replies.

About this Topic