AJAX and -1 response
You should end all “async” functions with die() or exit, otherwise WordPress does it for you returning -1.
You should end all “async” functions with die() or exit, otherwise WordPress does it for you returning -1.
I had got the ans. First you have to add following code in your function.php to call ajax in your template** add_action( ‘wp_ajax_demo-pagination-load-posts’, ‘cvf_demo_pagination_load_posts’ ); add_action( ‘wp_ajax_nopriv_demo-pagination-load-posts’, ‘cvf_demo_pagination_load_posts’ ); function cvf_demo_pagination_load_posts() { global $wpdb; // Set default variables $msg = ”; if(isset($_POST[‘page’])){ // Sanitize the received page $page = sanitize_text_field($_POST[‘page’]); $cur_page = $page; $page -= … Read more
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’, ‘callback’ => ‘yourstuff_test_endpoint’ ) ); } ); function yourstuff_test_endpoint( $request ) { $stuff = $request[‘stuff’]; return “Received “.esc_html( … Read more
There’s only one reason you get a 400 error with admin-ajax.php: The wp_ajax_{$action} or wp_ajax_nopriv_{$action} action has not been hooked with an {$action} that matches the action data parameter sent with your request. So either your callback is not hooked, or you’re not sending the action correctly. Your code is making both errors. You are … Read more
Until ajaxurl is always defined as of WP 2.8 you can simply remove the_ajax_script from here $.post(the_ajax_script.ajaxurl. You create the object the_ajax_script for the activate2 script but don’t but the code that uses this object in that file.
Ajaxify Form That Submits To Same Page To Display Post Data [closed]
It needs to be inside a div with id “content” in order to work (check the buddypress global.js file to see why!)
Save & Reset button in theme-option with Ajax (without refresh)
You need a die(); before the closing } of the function and you might want to add the relevant php header to tell the browser it’s content-type I wouldn’t worry about the browser returning the wrong content type. As long as your code loading the data treats it as JSON So for your function try … Read more
As otto implied in his comment, your code execution time is probably greater then the max php execution set in max_execution_time configuration directive in your php.ini, which is usually 30 seconds. You might be able to change that directive in php.ini or .htaccess, but it will only create a new problem as the user will … Read more