Path for ajax url in WordPress

How to call an ajax url in wordpress. Through a javascript file

I was using http://example.com/site/wp-content/plugins/pluginname/upload.php..

Read More

This is working but now I have changed the structure.

Now I want to make a call to a function inside a class

e.g
class A{


    function xyz(){
    include('upload.php');
    }
    }

Now, I am not calling upload.php through the javascript file but loading it inside the xyz function in the class.

So I want a way to call the xyz function from the javascript file.

Thanks

Related posts

Leave a Reply

2 comments

  1. Read this link http://codex.wordpress.org/AJAX_in_Plugins. Do you need to register wordpress hook wp_ajax.

    Add to your php code:

    add_action( 'wp_ajax_xyz', array($this, 'xyz') );
    

    In javascript

    var data = {
        action: 'xyz'
    };
    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    $.post(ajaxurl, data, function(response) {
        alert('Got this from the server: ' + response);
    });