Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I had problem using admin-ajax.php while creating one plugin. I had problem using "add_action( 'wp_ajax_ajax_action', 'ajax_action_stuff' )" in my plugin where i have used oop module. So I want to go with jquery native way like below :

$.ajax({
  url: "test.html",
  context: document.body,
  success: function(){
    $(this).addClass("done");
  }
});

Wordpress recommend to use admin-ajax.php for handeling ajax request. Is there any specific reason. Will i encounter any problem if go with native jquery ajax way.

share|improve this question
2  
What is the jQuery native way? jQuery sends a request to any URL, admin ajax is your URL. It's surely no different to any other jQuery ajax request? –  Joe Hoyle Jan 25 '12 at 9:39

2 Answers 2

I've used this method in quite a few applications until I found out about using admin-ajax.php, so pretty much simply put, no, I don't think it will cause any problems.

Although I do recommend using the method that WordPress describes! In my opinion it is much easier and works nearly the same (or better) as the method you are describing.

share|improve this answer
    
thanx for your prompt reply. I would be really grateful if u could show one nice example how to use it in oop structured plugin. i am getting confused regarding the callback function. –  Obhaso Jan 25 '12 at 9:31

There are a few reasons i can think of but the two most important would be:

  1. Data Security, take a look at this answer
  2. The use of WordPress functions inside you ajax php callback.

And as for using ajax with OOP development you can hook you callback function just like you normally would but add array with instance to the callback parameter, for example:

add_action( 'wp_ajax_ajax_action', 'ajax_action_stuff');

inside a class becomes

add_action( 'wp_ajax_ajax_action', array($this,'ajax_action_stuff' ));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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