Using conditional staements to load plugins

figured it out… The main problem with the scripts so just wrapped them in this for each plugin: function my_enqueue_javascript() { if (is_page(‘page’)) { //Include Javascript library wp_enqueue_script(”, plugins_url( ‘/js/ajax.js’ , __FILE__ ) , array( ‘jquery’ )); // including ajax script in the plugin Myajax.ajaxurl wp_localize_script( ”, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’))); } } … Read more

admin-ajax.php (aborted) error when using jQuery.get

Are there any Console js errors? The admin-ajax.php is WordPress’s built in way of dealing with ajax so you should probably do something like this, assuming .get() would also work: $.post(ajaxurl, data, function(response) { alert(‘Got this from the server: ‘ + response); }); http://codex.wordpress.org/AJAX_in_Plugins

Accessing an API with jQuery and AJAX

There are a few things going on with your functions.php file that may be the issue. You should be using wp_enqueue_scripts action to enqueue your script. The first parameter of wp_localize_script() should match the id of the file you’ve enqueued. You also need to add a no_priv version for your Ajax call if it needs … Read more

wp_ajax handler with multiple class instances

Your McAdmin seems fine – the problem is likely one of two reasons: Another AJAX hook for blubb is terminating the script before McAdmin::get_vehicle You need to add the same hook for wp_ajax_nopriv_blubb – for non-logged in AJAX requests (otherwise it fails silently). If neither is the cause, you need to do a little HTTP … Read more

admin ajax php success returns 0

Add die(); to the end of the function handle ajax. Add return false; after jQuery.ajax function tw_pages_results() { //stuff die(); } jQuery(document).ready(function() { jQuery.ajax({ type : “post”, dataType : “html”, url : “<?php echo site_url(); ?>/wp-admin/admin-ajax.php”, data : {action : “tw_pages_results”, ‘page’:0, ‘itemsperpage’:<?php echo $item_per_page; ?>, nonce: “<?php echo $tw_pages_nonce; ?>”}, success: function(response) { jQuery(“#results”).html(response); … Read more

Why AJAX response 0!

First, don’t enqueue on the init action. Enqueue on the wp_enqueue_scripts action for the front end, or the admin_enqueue_scripts action for the back end. Second, the wp_ajax_* action will only work for logged in users. For non-logged in users, you must use the wp_ajax_nopriv_* action instead. If it needs to work for both, then you … Read more

Calling a class method instantiated by ajax call in wordpress [closed]

You class method need to be static to be access without initializing the class or public in order to access from the class itself without reference &. And the variable $this->itemsClass also need to be public. So the workaround is – class Plugin { public $itemsClass; function __construct() { add_action(‘wp_ajax_list_items’, array( $this, ‘list_items’ )); } … Read more