1

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..

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

2 Answers 2

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);
});
0

Did you see this questions:

  1. how to call ajax on frontend of wordpress
  2. Wordpress: how to call a plugin function with an ajax call?

And i think Getting Started with AJAX & WordPress Pagination helps you too.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.