Tag Info

New answers tagged

2

To pass data from js back to PHP simplest way is use json_encode or, in WP, its wrappers wp_send_json, wp_send_json_error and wp_send_json_success. Usage example: On PHP side function get_latest_product_meta() { $post_id = (int) filter_input(INPUT_GET, 'post_id', FILTER_SANITIZE_NUMBER_INT); $post_id or wp_send_json_error(); // array_shift ...


0

The best solution I found was a small library. https://github.com/CalderaWP/dismissible_notice It is backward compatible till WordPress 3.8.


0

I think in your code you must add this line for ajax acting jQuery.ajax({ type : 'POST', url : '<?php echo admin_url('admin-ajax.php'); ?>', data : { action : 'vg_show_post_id', post_id: $post_id, data-id: true }, ),


0

wp_ajax_{my-action} action hook is only for admin side. For frontend you must use wp_ajax_nopriv_{my-action}. You can combina both if the ajax action is for both sides. For example: add_action('wp_ajax_filter_search', 'filter_search_result'); add_action('wp_ajax_nopriv_filter_search', 'filter_search_result'); Also, don't forget, never, to die or exit at ...


0

So, after hours of searching, I finally found where was my problem : another method in my class interfered with my ajax authentication system.


0

I think you need to start session at init action, find the piece of code given below.. may be helpful to you. :) add_action('init','vg_session_start'); function vg_session_start(){ if( !session_id() ) session_start(); } ...... your code.....


0

Not necessary, you echo the value on the traitement page, and in your ajax request, you get put the echo in a variable, like : resultats = ajax.responseText;


0

You cannot pass absolute URLs in WordPress. Use ajax_for_frontend.ajaxurl in place of absolute URL. Try using this (untested) - jQuery(document).ready(function() { var numberOfPromos = 4; jQuery.ajax({ url: ajax_for_frontend.ajaxurl, type: 'post', data: { action: 'get_number_of_promos', }, ...


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() ); }


0

I want to suggest this plugin. Do what you need, I think: https://github.com/33themes/ttt-loadmore . We will publish this plugin in the wordpress.org repo, but the documentation is not ready :)


0

In your ajax call, Just echo $results; Then do die(); Eg: echo $results; die();


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

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 : ...


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 ); } ...


0

You could use .ajaxComplete, as mentioned by @onetrickpony in http://wordpress.stackexchange.com/a/36597/57034, except do it globally on document, as mentioned in http://api.jquery.com/ajaxcomplete/, then filter based on action: add_action( 'admin_print_footer_scripts', function () { ?> <script type="text/javascript"> jQuery(function ...


0

Simpler steps: 1) in functions.php,add: add_action('init','my_wpEditOUPUTT');function my_wpEditOUPUTT(){ if (isset($_POST['Give_me_editorrr'])){ wp_editor( '' , 'txtrID_'.$_POST['myNumber'], $settings = array( 'editor_class'=>'my_class', 'textarea_name'=>'named_'. $_POST['myNumber'], 'tinymce'=>true , 'media_buttons' => true , ...


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.


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 ...


0

Plugin Class File: function __construct() { add_shortcode('user_registration_form', array($this, 'shortcode')); wp_register_script('product-serial', plugins_url('bootstrap/js/product-serial.js', __FILE__),array('jquery')); //custom jquery for product serial wp_enqueue_script( 'product-serial' ); //custom jquery for product ...


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' ));


0

You should try this plugin, this worked best when I needed similar on one of the blogs. Ajax Load More: It's available on WordPress repo.


0

A very simple experiment... add_action('admin_init','get_header'); add_action('admin_init','get_footer'); ... will demonstrate that the get_header() and get_footer() functions work on the back end as well as the front, though you will need to adjust for numerous markup problems and other issues. Honestly, you question seems to be "how do I get the site ...


0

You can use like this for send ajax... function my_action_javascript() { ?> <script type="text/javascript"> jQuery(document).ready(function ($) { var data = { 'action': 'my_action', 'whatever': '1' }; $.post(ajaxurl, data, function (response) { if ...


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 ...


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 ...


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($) { ...


0

Thanks to @websupporter I managed to find a solution to my problem. I have used this inside my Ajax function: success: function(data){ jQuery(data).find('.message').appendTo('#login-error'); } And in the php code I have done this: ... if(empty($username)) { echo "<span class='message error'>Please enter username.</span>"; exit(); ...


0

How can I show these errors inside the Ajax success or error functions? The jQuery error is triggered, when the request itself fails, for example timeout and others. See the jQuery documentation. The error messages, which are produced by PHP appear only on request success. To display these, you could do for example: success: ...



Top 50 recent answers are included