jQuery and Ajax callback
-
Hi everyone,
I’m starting to work with jQuery and Ajax inside a wordpress plugin for the first time and I’m having lots of issue. I’ve read the guide but something is missing anyway. I’m doing a simplce script that read text from a textfield and print it inside some element. I have 3 file :– page.php : the page with jquery e ajax call
– pluginpage.php : the main plugin page
– action.php : the php file that elaborate the ajax callPage.php :
jQuery("#button").click(function() { var text_capture = jQuery("#text").val(); jQuery.post(my_ajax_obj.ajax_url, { _ajax_nonce: my_ajax_obj.nonce, action: "text_writer", text: text_capture }, function(result) { jQuery("#parag").append(result); }); }); HERE ALL THE HTML ELEMENT WITH TEXTFIELD etc. etc.
Pluginpage.php :
require_once(PATH_PLUGIN_ETC....'action.php'); add_action( 'wp_ajax_text_writer', 'text_writer' );
Action.php :
function text_writer() { return $_POST['text']; }
Unfortunately this doesn’t append the text inside the textfield. Where am i doing wrong?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘jQuery and Ajax callback’ is closed to new replies.