Title: The proper way to have Javascript call PHP scripts
Last modified: August 19, 2016

---

# The proper way to have Javascript call PHP scripts

 *  [fatalx](https://wordpress.org/support/users/fatalx/)
 * (@fatalx)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/the-proper-way-to-have-javascript-call-php-scripts/)
 * 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

Viewing 1 replies (of 1 total)

 *  [Reuben](https://wordpress.org/support/users/greuben/)
 * (@greuben)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/the-proper-way-to-have-javascript-call-php-scripts/#post-1800757)
 * 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](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.

Viewing 1 replies (of 1 total)

The topic ‘The proper way to have Javascript call PHP scripts’ is closed to new 
replies.

## Tags

 * [custom fiels](https://wordpress.org/support/topic-tag/custom-fiels/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [XMLHttpRequest](https://wordpress.org/support/topic-tag/xmlhttprequest/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Reuben](https://wordpress.org/support/users/greuben/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/the-proper-way-to-have-javascript-call-php-scripts/#post-1800757)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
