Call php function with Jquery in wordpress using xampp
<p>I'm trying to do some basic stuff but my php code seems not to be called.</p>

<p>I have a button with an <code>onclick</code> event with points to a js function</p>

<pre><code>&lt;button type="button" onclick="tryphp()"&gt;go!&lt;/button&gt;
</code></pre>

<p>and this is in my index.php file.</p>

<p>Then I have a subfolder called js with inside my js file and the function is as follows</p>

<pre><code>function tryphp() {

jQuery.ajax({
        url: 'php/try.php',
        success: function (response) {//response is value returned from php (for your example it's "bye bye"
            alert('success!!!!');
        }
    });

}
</code></pre>

<p>finally, I have another subfolder "php" with inside my try.php </p>

<pre><code>&lt;?php

echo 'hello';

?&gt;
</code></pre>

<p>I expect the button to fire a "success!!!!" when clicked but nothing happens.
I'm trying to figure out if the error is in the "url" paramether of the ajax call?</p>

<p>The file structure is as below</p>

<pre><code>/main/index.php
/main/js/file.js
/main/php/try.php
</code></pre>

<p>Any help would be great!</p>

<p>Last but not least, my functions.php file is as follows</p>

<pre><code>    &lt;?php

function newtheme_script_enqueue() {
    wp_enqueue_style('style1', get_template_directory_uri() . '/css/newtheme.css', array(), '1.0.0', 'all');
    wp_enqueue_script('script1',get_template_directory_uri() . '/js/newtheme.js', array(), '1.0.0', TRUE);
    wp_enqueue_script('script1',get_template_directory_uri() . '/js/jquery.js', array(), '1.0.0', TRUE);
}

add_action('wp_enqueue_scripts','newtheme_script_enqueue');
</code></pre>

<p>and inside jquery.js I have downloaded the compressed version of jquery.</p>

<p>thanks in advance!</p>

<p>-----------UPDATE------------
SOLVED!</p>

<p>There were 2 mistakes:</p>

<p>-i did not specify the dependency in the script enqueue</p>

<pre><code>wp_enqueue_script('script1',get_template_directory_uri() . '/js/newtheme.js', array('jquery'), '1.0.0', TRUE);
</code></pre>

<p>-the path to the php file was missing the "template directory" part</p>

<p>Thanks everybody!</p>