Support » Fixing WordPress » Use AJAX-JQuery with WordPress

  • Hello,
    I have this code in a WordPress page:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    Show this:
    <div id="myDiv">
    </div>
    <script>
    $('#myDiv').load('ajax.php');
    </script>

    And this on ajax.php:

    <?php echo "Hello, World"; ?>

    ajax.php is uploaded on the WordPress root directory, but the script doesn’t show “Hello, World”. If I change line 7 in the html for:

    $('#myDiv').load('../ajax.php');

    It doesn’t work either. Neither does this:

    $('#myDiv').load('http://mysite.com/ajax.php');

    I know WordPress uses absolute paths for urls, but I need a relative path in this case, because the php file has to be executed locally.
    What do I do?
    Thanks.

  • The topic ‘Use AJAX-JQuery with WordPress’ is closed to new replies.