MySQL query in WordPress with AJAX

I would need to see your trigger function but it sounds like you just need to add event.preventdefault to the submit. This will block the page load while still executing AJAX. $(“form.searchCV_form”).submit(function(event){ event.preventDefault(); alert( “We’re not going anywhere now…” ); // j$.post… }); or $(“form.searchCV_form”).submit(function(e){ alert( “We’re not going anywhere now…” ); // j$.post… return … Read more

Submitting my form to the database and then redirecting to payment site

Good afternoon, I managed to sort this out. I have amended my functions.php to the following. function mcPaySubmit(){ global $wpdb; include(‘paygate.php’); $last = wp_get_recent_posts(array(‘numberposts’ => ‘1’, ‘post_type’ => ‘post’, ‘post_status’ => ‘pending’, ‘author’ => $user_id)); $purchase_post_id = $last[‘0’][‘ID’]; $purchase_days = $_POST[‘dext’]; $purchase_date = $_POST[‘mcTransactionDate’]; $purchase_amount = $_POST[‘totalDue’]; if($wpdb->insert(‘ac_purchases’, array( ‘purchase_post_id’ => $purchase_post_id, ‘purchase_days’ => $purchase_days, … Read more

Deploy Subcategories with Ajax not working

onclick=”cat_ajax_get(…)” looks for a function in the global Javascript scope. This line: jQuery(document).ready(function($){ hides everything from the global scope. So, this won’t work. You will have to use a completely different technique here. Do not set the onclick attribute. Instead attach the handler from inside your Javascript code: jQuery(document).ready(function($){ var links = $(“.filter a.ajax”); var … Read more

Ajax Function call is always returning 0 in front end(without plugin) [closed]

First things first You have a few errors in your code. The table for terms is called wp_terms instead of wp-terms The query $qry is not correct, the inner query has an invalid WHERE-clause: SELECT term_id as term_id FROM wp_term_taxanomy = ‘category’ should be SELECT term_id as term_id FROM wp_term_taxanomy WHERE taxonomy = ‘category’ Improvement: … Read more

wordpress ajax return 0

So, if you want it to fire on the front-end for both visitors users and logged-in users, you can do this: add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); add_action( ‘wp_ajax_nopriv_my_action’, ‘my_action_callback’ ); Example add_action( ‘wp_ajax_GetPostMedia’, ‘GetPostMedia’ ); add_action( ‘wp_ajax_nopriv_GetPostMedia’, ‘GetPostMedia’ );

Use ajax without a plugin?

Plugin code is just… code, it can go in a themes functions.php, or a plugin file, there’s no magical or special difference other than the order they’re loaded in, and the API calls are identical, work the same way etc because they’re the same. It’s just how the code is packaged For example, if you … Read more

Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?

Maybe It’s the Appropriate Answer for You! Accordingly to this question the more reasonable answer is to use wp_send_json() with (if only necessary) the wp_send_json_success() and wp_send_json_error() functions. They’ll return an JSON Object back to the AJAX Request and it will automatically die() for you. It will look something like this: add_action( ‘wp_ajax_origin’, ‘create_an_ajax_request_origin_form’ ); … Read more