Skip to content

Instantly share code, notes, and snippets.

@dshaw002
Created December 16, 2013 20:55
Show Gist options
  • Save dshaw002/7994249 to your computer and use it in GitHub Desktop.
Save dshaw002/7994249 to your computer and use it in GitHub Desktop.
Wordpress AJAX
//of your theme...
function test_ajax()
{
$pass = "empty";
if( isset( $_POST['passthrough'] ) ){ $pass = $_POST['passthrough']; }
die( json_encode( array("result"=>"true", "vars" => $pass) ) );
}
add_action( 'wp_ajax_nopriv_test_ajax', 'test_ajax' ); // if user is not logged in
add_action( 'wp_ajax_test_ajax', 'test_ajax' ); //if user is logged in
$('.deal-head-left').click(function(){
$.ajax({
url: 'http://162.243.11.26/wp-admin/admin-ajax.php',
type: 'POST', dataType: 'json',
data: { action: 'test_ajax', passthrough: 'Pass935JI'},
success:function(data){
console.log(data);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment