Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

Here, i have develop a simple demo for get a post data of depends on category without loading page using Ajax and jQuery. Here is a main category, sub category and post dropdowns : $args = array( 'orderby' => 'name', 'hierarchical' => 1, 'taxonomy' => 'category', 'hide_empty' => 1, 'parent' => 0, ...


0

There seems to be a big misunderstanding here about how hooks work, and how AJAX works. The reason that you can't hook into AJAX in footer.php is because footer.php is not loaded during an AJAX request. No templates are. When you run add_action() you are scheduling a given function to fire when that action is fired during the current request. When you load ...


-1

To be the absolutely last action to process on any WordPress hook, including AJAX, you can set your priority value to be the highest. You could use PHP_INT_MAX in the following manner: add_action( 'wp_ajax_my_action', 'my_ajax_action', 0, PHP_INT_MAX ); function my_ajax_action() { //Your code }


0

Made ajax call as a function to avoid the Console Error 400 Post. It opens the channel and I was able to get the parameters passed. counter.js jQuery(document).on('click','.counter',function(e){ testAjax(the_ajax_script.ajaxurl); }); function testAjax(link) { $.ajax({ url: link, type: 'post', data: { 'action': 'set_button_count', ...


2

Is it possible to bind a function to a filter hook via Ajax? No, because page requests are self contained. When you request something from PHP, everything gets loaded from a fresh clean slate. At the end of the request, that slate is discarded. This is different from say a Node application that is always running. So, if you make an AJAX request and ...


-1

Yes, like @fuxia says, include wp-load.php to get the WordPress API (wp_nav_menu included) to use. In your case: <?php include '../../../../wp-load.php'; This way you did is not wrong but there are better ways to use AJAX in WordPress: https://codex.wordpress.org/AJAX_in_Plugins Be happy, my friend!


2

You function name and your ajax action callback name should be same. add_action('wp_ajax_pdfAction','pdfAction_callback'); add_action('wp_ajax_nopriv_pdfAction','pdfAction_callback'); function pdfAction_callback(){ $post = $_POST['pdfAction']; echo "something"; wp_die(); } Please update your php code with the above. Currently, your php ...


0

Take a look at the codex for AJAX in Plugins. It provides example of how WordPress expects AJAX requests are made and how to return information back to the request in javascript. The request gets routed through admin-ajax.php which locates and action in PHP. The rest is up to you. Note: you must echo/print the content for it to be returned in the body of ...


0

The answer was that I had dequeued the woocommerce style sheets and fonts, adding the CSS back in made the tick marks appear .added:after { font-family: WooCommerce; content: '\e017'; margin-left: .53em; vertical-align: bottom; display: inline-block; }


1

Please try below code : script.js jQuery(function($) { var i; for(i=1;i<21;i++){ $('body').on('change', '#file'+i, function() { var file_data = $(this).prop('files')[0]; var id = $(this).attr('id'); var form_data = new FormData(); form_data.append('file', file_data); form_data....


2

You can add the function to both hooks: add_action('wp_ajax_ajaxTest', 'ajaxTest'); add_action('wp_ajax_nopriv_ajaxTest', 'ajaxTest'); But, there's a better way to do it, use a REST API endpoint: add_action( 'rest_api_init', function () { register_rest_route( 'yourstuff/v1', '/test/', array( 'methods' => 'POST', '...


1

No. You have to write only one function. For example, function ajaxTest(){ //your code } add_action('wp_ajax_ajaxTest', 'ajaxTest'); add_action('wp_ajax_nopriv_ajaxTest', 'ajaxTest');


2

This is happening because you have click event firing on ID jQuery('#przyciskUlubione').click(function() { The ID is always unique, there should never be more than one same ID in the HTML. You can achieve this using class. Assign the same class to all the buttons. Change your selector to class: jQuery('.przyciskUlubione').click(function() { add value ...


1

In order to make this work as you expect, you need to add the following lines in your constructor (depending on the requirements you have) add_action( 'wp_ajax_myfunction', array($this, 'myfunction') ); add_action( 'wp_ajax_nopriv_myfunction', array($this, 'myfunction') ); Note that wp_ajax_nopriv_myfunction executes for users that are not logged in. The ...


2

No, it is not possible. Nonce is generated on server as a function of domain name, user information, action, time, etc. This is made especially to distinguish requests from one server to another.


0

What you're looking to accomplish isn't really pagination. That threw me off initially. You're building a navigation that will be site-wide. If that's the case, you can either capture the ID from the url (this is not very performant) or add the ID to the markup. This example shows you how to add the ID as a data attribute on the menu's anchor tag: ...


1

My guess is that the shipping method isn't initialised when you make an ajax call. Try moving your actions directly into your init function. EG: function checkAjax(){ print_r($_POST); exit; } function dhlsweden_shipping_method_init() { //use checkAjax since you don't have access to your shipping method class. If this is the case then you need ...


0

The problem is that you're attempting to use the arguments for the jQuery AJAX API with the native Fetch API. Specifically, the problem is that the JS Fetch API doesn't support a data argument. For an admin-ajax.php request to work in WordPress the $_REQUEST['action'] property needs to be populated, and to do this with the Fetch API you need to pass a ...


0

So, the success function in the ajax function has to look like the following: success: function(html){ console.log('success'); $( '#results' ).html(html); $( '#results .usermanagement_select' ).select2({tags: true}); }


0

This appeared to be a bug in WordPress, coming back to this and upgrading to version 5.2 the problem seems to have been fixed for some reason the has_action was failing to find the action unsure why but it seems to have been fixed.


0

I resolved this issue by using the wp-ajax environment. Essentially, I created the callback function for the comment_row_actions filter which created the link pointing to admin-ajax.php in the admin directory with a query string. Then I created the add_action to run in the wp_ajax environment with a redirect back to the referring page. I couldn't come up ...


2

I manage to solved it by adding this code (at the bottom) to the YOUR BLOG THEMES my path : wp-content/themes/twentysixteen/function.php: function ws_register_images_field() { register_rest_field( 'post', 'images', array( 'get_callback' => 'ws_get_images_urls', 'update_callback' => null, ...


Top 50 recent answers are included