Created
October 3, 2012 15:39
-
-
Save garyc40/3827632 to your computer and use it in GitHub Desktop.
WordPress AJAX JSON
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
// embed the javascript file that makes the AJAX request | |
// don't forget to specify 'json2' as the dependency | |
wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js', array( 'jquery', 'json2' ) ); |
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
wp_enqueue_script( 'json2' ); | |
// don't forget to specify dependency | |
wp_enqueue_script( 'myjQuery', plugin_dir_url( __FILE__ ) . 'js/jquery.1.4.2.js', array( 'json2' ) ); |
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
wp_enqueue_script( 'json2' ); |
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
jQuery.post( MyAjax.ajaxurl, { action : 'myajax-submit' }, | |
function( jsonString ) { | |
// use JSON parser on the response string instead of | |
// specifying the response type as json | |
var object = JSON.parse(jsonString); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment