PHPSOFT SOLUTIONS LOGO
  • Home
  • About Us
  • Contact Us
  • Contact Us
  • Blog
  • Online Courses
  • Contact US

how to use ajax in wordpress

There are few simple steps to use ajax in wordpress:
– ajax calling template/page file element (button / link)
– ajax calling and response handler script in js/jqery
– wordpress hooks defined to handle ajax functions
– php function file to define functions to operate.

Files used in wordpress:
– any template file or page or post and for js ajax calling

jQuery(document).ready(function(){
jQuery('#wp_agent_sync').click(function(){
jQuery.ajax({
type : "post",
dataType : "json",
url : '',
data : {action: "podiocall",method:'agent'},
success: function(response) {
alert(response.msg);
}
}) ;
});

– function.php for defining ajax hoooks
example :
add_action("wp_ajax_podiocall", "podioListingCall");
– function.php for php function definition or any included library.
function podioListingCall()
{

$method = in_array($_POST['method'],array('listing','agent')) ? $_POST['method'] = false;
if($method==false) echo json_encode(array('response'=>'fail','msg'=>'Unknown method called!'));
else
{
echo json_encode(array('response'=>'success','msg'=>'podio called,Thanks'));
}
die();
}

Thanks for reading!

Posted on March 2014
Category: Wordpress

Categories

  • Blog
  • phonegap
  • PHP Frameworks
  • php-jquery
  • system
  • Wordpress
  • Yii

Post navigation

Previous post

Phonegap access origin error resolved

Next post

wordpress insert post data and custom fields


PHPSOFT SOLUTIONS LOGO

Our mission is to satisfy our customers to the best.Money is the source nowdays, the trust of how we can use your money in the best way is build by us.The core value of php soft solutions is to provide the best service to our customers in a great manner.

Contact

PLOT NO. C157, The Groove, Industrial focal point, Phase7,MOHALI, SAS Nagar, Punjab, 160055

8146501814

contact@phpsoftsolutions.in

Pages Links
  • WordPress
  • Yii
  • PHP Frameworks
  • php-jquery
  • system
  • phonegap

© 2025 PHPSOFT SOLUTIONS