How to use Ajax in wordpress with Jquery

In this post I want to explain that how to use Ajax in wordPress and also How its work in wordpress. There are many ways using ajax in wordpress. Ajax is a technique for display content on page without refresh page It’s a fast and smooth way for displaying content, and as a result Ajax is now used in many various ways on a website, such as submitting blog comments, posts and uploading files. You can even make your website completely Ajaxified, so that each page of your site will load asynchronously.

You may already know that using ajax in wordpress slightly different to outside of wordpress, You will need to consider somethings and also must be need to knowledge of wordpress hooks and functions for use ajax in wordpress.

In wordpress no need to include jquery file because jquery already included in wordpress, And in wordpress two things are most important for ajax first all Every Ajax request goes to admin-ajax.php and  each and every request goes to create two  action hooks.

Action hooks takes two parameters first one action and second function name, In wordpress ajax two hooks are used first wp_ajax and second wp_ajax_nopriv you can see in given example.




first hook is executed for guest user and second hook is executed for login user, this is great way for control access for users without any conditions.

Example

In this example we fetch post meta field value and increment that filed value and again update it.  Now read ajax call code which given below.

 

 

5 thoughts on “How to use Ajax in wordpress with Jquery”

  1. Nice read, I just passed this onto a colleague who was doing a little research on that. And he just bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch! “Not only is the universe stranger than we imagine, it is stranger than we can imagine.” by Sir Arthur Eddington.

    Reply
  2. Good post however I was wanting to know if you could write a litte more on this subject? I’d be very grateful if you could elaborate a little bit more. Thanks!

    Reply
  3. I do not even know the way I ended up here, however I thought this submit used to be great. I do not realize who you are however certainly you are going to a famous blogger when you aren’t already 😉 Cheers!

    Reply
  4. I’m really enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Outstanding work!

    Reply

Leave a Comment