Tag Info

New answers tagged

0

First of all, to resolve the javascript conflict I've set up a simple tl_custom.js under my theme js/ folder, with the following code jQuery(document).ready(function($) { // Remove handler set by themes/Divi/js/custom.js at line 2642 $( 'a[href*=#]:not([href=#])' ).off(); }); Then I add the script with the following code in functions.php ...


0

I might be off track here, but would removing the return false; from the javascript you posted help? return false; in a click function is like saying: event.preventDefault(); event.stopPropagation(); I think this is why your other function is not firing as there is no restriction to having multiple handlers bound to the same event on an element. ...


0

From a purely WordPress perspective, the only solution I see would be to copy the script to your child theme and make edits to it to remove the conflict. If the parent theme uses get_template_directory_uri to reference the path to the script, you'll also have to dequeue the original, and enqueue your modified version. If the script is loaded using ...


0

You could achieve this with a little bit of jQuery: Create this file within THEMEFOLDER/js/ called field-clear.js and replace #formID with the ID of the form you would like to reset: //Code runs when an ajax request succeeds jQuery( document ).ajaxSuccess(function( event, xhr, settings ) { //Check ajax action of request that succeeded ...


1

Your AJAX callback method should be outputting something followed by a die() statement. function wp_insert() { ..your code echo $whatever_your_results_are; // die(); } I would also recommend against prefixing your custom methods with wp_. That should be reserved for WordPress and will cause confusion to other developers - and probably you ...


1

First of all, some recommended reading - AJAX in Plugins. I realise this is not a plugin, but the Codex is still relevant, and as you'll see in the PHP section, you can use the WP AJAX handler to handle front end calls as well as those from the admin area. Javascript For this, you would be better advised putting your JS in an external *.js file that is ...


0

ave you tried to put it in the Shortcode-function? I would suggest this: function my_shortcode() { ?> <script> alert('test') </script> <?php } add_shortcode( 'my_shortcode', 'my_shortcode');


0

Just had the same issue. The $_REQUEST is empty because angulars $http sends its data as JSON per default. Yu have to send the data as formdata: var app = angular.module('foo', []); app.config(function ($httpProvider) { // send all requests payload as query string $httpProvider.defaults.transformRequest = function(data){ if (data === ...


1

What would you do if the user uses a proxy and randomizes his IP address? There are numerous browser plugins to simplify that to a click of a button to download multiple times. The same goes for cookies. Aside from that you are trying to collect data that allows to identify users, which is illegal in lots of countries. What (could) work much better is a ...


-1

if ajax returns zero, the function bound is not registered properly have a read: http://arresteddeveloper.net/woocommerce-get-variation-description-variation-select-changes/ this might point you in the right direction


0

This is a javascript issue. You have to prevent form submission to stop the page from reloading. See event.preventDefault() in jQuery docs. jQuery("#Submityourskill").click(function(event){ event.preventDefault(); // the rest of your code });


0

Currently I'm assuming that is is backend (front end is slightly different), but it's very easy to implement on the frontend if required. You are correct in thinking that because you haven't used the WordPress admin-ajax.php file, all the goodness of WordPress is missing. Fortunately this is easily fixed. Before continuing I recommend that you take a look ...


0

Coming back to this on a new application. I just solved this using Angular, and a similar approach could be used with vanilla JS. First, give Javascript access to the admin-ajax.php URL, something like: echo "<script type='text/javascript'>var ajaxurl = '".admin_url('admin-ajax.php')."'</script>"; Next, in functions.php, register the action ...


1

You right Bruno, the AND is optional, I tried without it and it is now working, not sure why, here is the code : function GetBrandChildren() { $output = ''; //retrieve POST data sent by AJAX $parent_id = $_GET['parent_id']; //Define query arguments $args = array( 'post_type' => 'aromes-type', 'meta_query' => array( ...


0

Here is an example of a class that I use to automatically create ajax callbacks from methods in the class. It acts almost like a router. class AjaxEndpoint { //Loop through all functions and add them as ajax actions public function registerActions() { foreach ( get_class_methods( $this ) as $method_name ) { if ( $method_name !== ...


0

Try using this: $args = array( 'post_type' => YOUR_POST_TYPE, 'meta_query' => array( array( 'key' => '_wpcf_belongs_marque-type_id', 'value' => $parent_id ) ) ); In your loop set an else statement just to sure that you query isn't returning zero results: if ( ...


3

it seems the latter only accepts x-www-form-urlencoded That's not completely true. WordPress admin-ajax.php takes the action from $_REQUEST['action'] and $_REQUEST is equal to: array_merge($_POST, $_GET); But what many people don't realize is that $_GET in PHP is not the data was sent to page using HTTP GET method, in fact, you can use whatever ...


0

admin-ajax.php was designed to work against jQuery, most likely if you do not make the conversion on the JS site you will have to do it on the server side to make it work. Instead you can add your own "end point" that can process json. The biggest problem with this approach is the query that WP runs on "front end" urls.


1

Your problem is that you are checking for nonce and the nonce is stale. It is hard to make a specific comment about the need of using nonce in your case, but in general nonces should be used only for data submission not query.


0

Wrapping it in a function and then adding the following did the trick: add_action( 'wp_footer', 'my_ajax_script' ); // Write our JS below here Was all it took


0

Its an old question however would like to answer for other people Within ajax function hooked to wp_ajax do this. $url = wp_get_referer(); $post_id = url_to_postid( $url );



Top 50 recent answers are included