Tag Info

Hot answers tagged

4

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl = 'http://my-site.co.uk <?php bloginfo("wpurl");?>/wp-admin/admin-ajax.php'; To: var ajaxurl = "<?php echo esc_js( admin_url( 'admin-ajax.php' ) ) ?>"; Note: from your code and description I'm assuming you are generating the jQuery code within ...


3

1) Why use admin-ajax.php instead of encoding your json in a separate file like themes/example/json.php and encode your data there? Using admin-ajax.php means that the WordPress Core is loaded and available. WIthout that, you would need to hand load the files you need, which is a complicated process and prone to failure if you don't know the Core ...


3

Your AJAX add_action and associated callback function shouldn't be inside view-create-rooms.php, move it into your main plugin file. When an AJAX request is sent, you're making a new separate request to the server, so your submenu page will not be loaded and your AJAX action never gets added to the queue.


3

Have you tried returning an array instead? wp_send_json($an_array_of_your_vals); And then parse the array in the success function? success: function( data ) { var obj = jQuery.parseJSON(data); if( obj.arg_1 ) { $('selector').append( obj.content ); } else if( obj.arg_2 ) { $('other_selector').append( obj.content ); } ...


1

There's two parts to this, the javascript ajax call needs specific variables included: $.ajax({ type: "GET", url: SSL_Ajax.ajaxurl, cache: false, dataType: "jsonp", crossDomain: true, data: { action : 'ajaxSSL', ajaxSSLNonce : ...


1

If you check the source for admin-ajax.php you will notice that the admin_init hook fires and that the system checks $_REQUEST['action'] for hooks. Given that, you could hook to admin_init, check the "request" super global, construct wp_ajax_* and wp_ajax_nopriv_* values, then use has_action() to see if anything is hooked in.


1

You need to also check it's not an AJAX request inside your hook: if ( ! current_user_can( 'administrator' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { wp_redirect( home_url() ); }


1

WordPress does not use or affect PHP Sessions in any way. Therefore, the session functions will work exactly the same whether you're using WordPress or plain PHP or AJAX requests or anything else. However, PHP Sessions depend very heavily on your specific PHP configuration. If you don't have the PHP Session settings configured correctly in the PHP.INI, then ...


1

Put below code in _construct() function and change action name to get_product_serial_callback :- add_action( 'wp_ajax_get_product_serial_callback', array($this,'get_product_serial_callback') ); add_action( 'wp_ajax_nopriv_get_product_serial_callback', array($this,'get_product_serial_callback' ));


1

You need to add your class of fi-shopping-cart to both instances of the cart link element: In the shorter, single-line snippet you've used your theme file, and in the the custom code you added to your functions.php file. If the custom class is present in only one snippet, it will be replaced when the other is loaded in. The updated code is below. After ...


1

admin-ajax.php is part of the WordPress AJAX API, and yes, it does handle requests from both backend and front. here what i figure-out for your question that is: 2) How does admin-ajax.php work? for the logic you can visit here. This assumes you already know how to enqueue JavaScript, etc. JavaScript Piece: jQuery(document).ready(function($) { ...



Only top voted, non community-wiki answers of a minimum length are eligible