1

js file in content/themes/themename/js/main.js in this file I am trying to do an ajax call to this file content/themes/themename/lib/file.php

this is how my ajax call looks like

    $.ajax({
    type: 'POST',
    url: 'file.php',
    success: function(result) {
        var data = jQuery.parseJSON(result);
        console.log(data.name);
        }
    });

but the url is not working anyone can help me out?

I have tried ../lib/file.php too

3
  • check the php file path. Commented Feb 24, 2016 at 9:21
  • Read this -> codex.wordpress.org/Plugin_API/Action_Reference/… Commented Feb 24, 2016 at 9:23
  • it's this path: /content/themes/themename/lib/getsearchoptions.php Commented Feb 24, 2016 at 9:23

3 Answers 3

1
 $.ajax({
    type: 'POST',
    url: '<?php echo get_stylesheet_directory_uri();?>/lib/file.php',
    success: function(result) {
        var data = jQuery.parseJSON(result);
        console.log(data.name);
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

0

maybe you can try with the path that relative to the root directory ex :

$.ajax({
    type: 'POST',
    url: '/wordpress_site/wp-content/themes/themename/lib/file.php',
    success: function(result) {
        var data = jQuery.parseJSON(result);
        console.log(data.name);
    }
});

Comments

0

I fixed it by doing this in my body tag of my header.php file

data-theme-url="<?php echo get_stylesheet_directory_uri(); ?>

and use the url in my javascript like this

url: $('body').data('theme-url') + '/lib/file.php',

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.