Ajax submit result opens in admin-ajax.php
You’re not passing the event object in your submit function, so e.preventDefault(); doesn’t stop the form from being submitted. $(‘#form_id’).submit(function(e) { // <— event object ‘e’ e.preventDefault();
You’re not passing the event object in your submit function, so e.preventDefault(); doesn’t stop the form from being submitted. $(‘#form_id’).submit(function(e) { // <— event object ‘e’ e.preventDefault();
You are mixing things up a bit here. What you are currently doing is adding an optional layer on top of your website. For users with JavaScript you make the page load look different, as you use custom events/effects, instead of relying on the browser. admin-ajax.php is relevant, when you want to access specific methods … Read more
Ok, so I don’t know if this is the best way, but it’s working for now. Within my OOP class (I have a custom plugin to override a WC plugin): remove_action( ‘wp_ajax_wc_function’, array( WC_Parent_Class, ‘wc_do_stuff’ ) ); remove_action( ‘wp_ajax_nopriv_wc_function’, array( WC_Parent_Class, ‘wc_do_stuff’ ) ); add_action( ‘wp_ajax_wc_function’, array( __CLASS__, ‘my_override_do_stuff’ ) ); add_action( ‘wp_ajax_nopriv_wc_function’, array( __CLASS__, … Read more
The action: ‘ajax_contact’ part in: var data = $form.serialize(); console.log(data); $.ajax({ url: ajax_contact.ajaxurl, dataType: ‘json’, action: ‘ajax_contact’, data: ajax_contact.data, is most likely the cause here, that your ajax request is failing. Move the action part into the data set instead. Since you’re serializing the form data, you could try to add: <input type=”hidden” name=”action” value=”ajax_contact” … Read more
is_single returns if there is a single page displayed within the actual server process. Within the Ajax-Function, nothing is “displayed”, you’re doing Ajax. To check if the currently displayed object in your Browser is a single object, you need to transfer the information about this from the server process that serves your Browser to the … Read more
If it is not HTML, it does not need HTML escaping, if it is not JS, it does not need JS escaping. All escaping is context based. In general You should probably just avoid sending “text” in response and focus on sending data which is “converted” into whatever is the relevant DOM structures, either directly … Read more
Step 1: Learn how to use AJAX in WordPress Plugins/Themes. The trick is that your Javascript doesn’t get the Stuff from Beta Site, your Javascript calls a PHP-Function you coded that itself gets the Stuff. Step 2: Keep using the Transients. Check within your Ajax Callback, if there is a transient. If there is, return … Read more
If your requests take 3-5 sec to finish, then there is most likely something else going on. The admin Ajax itself won’t take that much to load. You might be having some heavy plugin, or having some hooks running expensive meta queries on load. You can try the REST-API, which is slightly faster than Admin-Ajax. … Read more
The action in the Ajax call must be the name of the action on the add_action without the wp_ajax_nopriv.* for example: var data = { action: ‘fmsapi_refresh_hybrid_schedule’, year: ‘2017’, event: ‘ONOSH’, team: ‘4783’ }; You are targeting a class named select_team but this isn’t anywhere in your code. This is why your Js code cannot … Read more
Modify the following code I have added action in it. $(‘#btnDoCalculation’).click(function(e){ var formData = $(‘#interest_calculator’).serialize(); $.ajax({ type: ‘POST’, url: ‘<?php echo admin_url(‘admin-ajax.php’);?>’, data:formData, dataType: ‘json’, action:calculate_investor_interest encode:true, }).done(function(data){ if(data.success){ console.log(data); var results = data.calc_results; var newData = results.reduce(function(collection, element){ var rowData = {}; //create a new empty row element.reduce(function(collection, element){ //put the elements into the … Read more