Last active
April 23, 2018 02:55
-
-
Save aslamdoctor/0a2e2bc1f77d8806e1a5c158ca8de725 to your computer and use it in GitHub Desktop.
Ajax with Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The HTML | |
wp_localize_script( 'amd_app_js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); | |
// The PHP | |
add_action( 'wp_ajax_get_exhibitors', 'get_exhibitors_callback' ); | |
add_action( 'wp_ajax_nopriv_get_exhibitors', 'get_exhibitors_callback' ); | |
function get_exhibitors_callback() { | |
$alphabet = @$_POST['alphabet']; | |
$supplier_type = @$_POST['supplier_type']; | |
var_dump($_POST); | |
die(); | |
} | |
// The Javascript | |
$.ajax({ | |
type: 'POST', | |
url: ajax_object.ajax_url, | |
data: { | |
'alphabet' : 'A', | |
'supplier_type' : 'Worker', | |
'action': 'get_exhibitors' | |
}, success: function (result) { | |
alert(result); | |
reset_exhibitors(); | |
}, | |
error: function () { | |
alert("error"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment