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.

currently I can only do it in a normal non-wordpress way.

So, does wordpress provide a solution for this circumstance?

share|improve this question
    
Please click the ajax and search through the answers. –  kaiser Feb 15 '12 at 10:33
    
i answered that here too: wordpress.stackexchange.com/questions/42159/… –  helgatheviking Feb 15 '12 at 15:27
    
thank u, guys. really appreciated –  castiel Feb 16 '12 at 1:05
    
possible duplicate of What's the preferred method of writing AJAX-enabled plugins? –  Chris_O Aug 27 '12 at 1:17

1 Answer 1

up vote 2 down vote accepted

It does, have you look at Bainternet's solution to this question and my answer to this question?

To summarise, you need to post the request to the WordPress' admin-ajax url. If the ajax is for use on the admin-side then this url should already be available as the javascript variable ajaxurl. If this is for use on the front-end then you'll want to get the admin url:

<?php echo admin_url('admin-ajax.php'); ?>

inside your javascript file (see my solution linked above). WordPress then files the following actions:

//for logged in users only 
add_action('wp_ajax_MY_ACTION', 'my_ajax_function');

//for non-logged in users 
add_action('wp_ajax_nopriv_MY_ACTION', 'my_ajax_function');

Where MY_ACTION is the action sent with the AJAX request. You can hook the function that deals with the request, (in this example my_ajax_function) onto the appropriate hook(s). This function should echo the response.

For more information see the above answers, and the Codex on Ajax in WordPress.

share|improve this answer
    
thanks man,really helpful –  castiel Feb 16 '12 at 0:59

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.