WordPress AJAX – WordPress jQuery AJAX POST Request

WordPress AJAX – WordPress jQuery AJAX POST Request

In this Post We Will Explain About is WordPress AJAX – WordPress jQuery AJAX POST Request With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to use ajax in wordpress theme Example

In this post we will show you Best way to implement WordPress AJAX Example, hear for simple ajax example in wordpresswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

how to use ajax in wordpress with javascript or jquery step By Step

Step 1 : First we will see the PHP side – > Server side Source code:-

add_action(“wp_ajax_ActionForJS”,”yourfunctioncallbecalled”);

Step 2 : we need to init the your Action name for jquery Ajax request exten name Like as a wp_ajax_ + name.

Step 3 : The second argument is the simple callback function using jquery which will be run and executed at the time of jquery Ajax request. For simple simplicity we could create both of them and each like this:-

add_action(“wp_ajax_livefunctionName“,”liveFunctionName”);

Step 4 : Now init or define the call back simple function as follow:-

function ”liveFunctionName”()
{
		$respnose= new WP_Ajax_Response;
		if(!current_user_can(‘manage_options’) )
		{
		$respnose->add(array(‘data’=>’error’,’supplemental’=>array(‘message’=>”You not or  don’t have any permission!”)));
		}
		else
		{
		$respnose->add(array(‘data’=>’success’,’supplemental’=>array(‘message’=>”complete”)));
		}
	$respnose->send();
	die();
}

Step 5 : Here is the simple client side Browsers JavaScript to make a jquery Ajax Request.

function button_click(){

		data={ “action”:””liveFunctionName”“,“option”:” your simple data to be passed” };
		jQuery.post(ajaxurl,data,function(data)
		{
		var mysta=jQuery(data).find(‘response_data’).text();
		var message=jQuery(data).find(‘supplemental message’).text();
				if(mysta==’success’)
				{
				alert(“Success:”+message);
				//some code...
				}
				else
				{
				alert(“error:”+message);
				//some code...
				}
		}
		);

}

Example

I hope you have Got What is how to use jquery ajax in wordpress And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Jquery Datatable listing json Server side in Php Mysql and Ajax
  2.   WordPress AJAX URL GET POST Call PHP Function
  3.   Ajax File Upload without refreshing using jQuery and PHP
  4.   Wordpress set and get User last login Date and time
  5.   Woocommerce get price in custom loop
  6.   Google API Line Chart with JSON PHP & Mysql
  7.   $timeout Service using Angular Example
  8.   Laravel 7 jQuery Ajax Form Validation Example
  9.   Paypal Payment Gateway Integration using Java
  10.   Laravel whereRaw havingRaw and orderByRaw Example