How to pass jQuery ajax URL value

Ajax url should be set to wp-admin/admin-ajax.php as ajax requests should be handled via wp-admin/admin-ajax in wordpress. if ajaxurl is not defined you can get it by defining html attribute data-url as data-url=”<?php echo get_admin_url().’admin-ajax.php’?>”. jQuery(document).ready(function($){ $(“#wp-submit”).on(‘click’,function(e){ e.preventDefault(); username = $(“#userName”).val(); password = $(“#passWord”).val(); ajaxurl = $(this).data(‘url’); $.ajax({ type: “POST”, url: ajaxurl, data : { … Read more

Simple jQuery Click Not Working, though console log recognizes the function [closed]

When enqueuing a script, you should state your script’s dependencies. In your case, it’s jQuery. Enqueue your script in the following way: wp_enqueue_script ( ‘my-plugin’, ‘path/to/the.js’, array( ‘jquery’ ) ); You may also want to ensure that your script IS loaded in the footer, by setting the last argument to true: wp_enqueue_script ( ‘my-plugin’, ‘path/to/the.js’, … Read more

jQuery on Underscores menu

You haven’t passed jquery as a dependency for your script, and you are using the dollar sign too, which is not directly supported in WordPress due to conflict. First, pass jQuery as a requirement while enqueuing your navigation.js: wp_enqueue_script( ‘themename-navigation’, get_template_directory_uri() . ‘/js/navigation.js’, array(‘jquery’), ‘20151215’, true ); Then, wrap your code in a self invoking … Read more

wp_enqueue_script being ignored in custom theme

You can better try this way and let me know. function wpb_adding_scripts() { wp_enqueue_style( ‘slider’, get_stylesheet_directory_uri() . ‘/css/calculator.css’); wp_enqueue_script(‘jquery’); wp_enqueue_script(‘calculator_script’, get_stylesheet_directory_uri() . ‘/js/calculator.js’); } add_action( ‘wp_enqueue_scripts’, ‘wpb_adding_scripts’ );

admin-ajax.php HTTP400: BAD REQUEST – The request could not be processed by the server due to invalid syntax

You can’t send the data to admin-ajax.php as JSON: data: JSON.stringify({ action: “process_coupon” }), For the wp_ajax_ actions to be fired, WordPress checks $_REQUEST[‘action’], but this is not populated by PHP when the form is submitted as JSON. The correct way to send the request with jQuery is to pass the data like this: data: … Read more

modifying a template and adding jQuery to it

Rather than modifying the template, since you’re going to need jQuery anyway, you can do this.. Add to the functions.php add_action( ‘wp_enqueue_scripts’, ‘blogroll_toggles’ ); function blogroll_toggles() { if( is_page_template( ‘bookmarks.php’ ) ) wp_enqueue_script( ‘blogroll-toggle’, get_bloginfo( ‘stylesheet_directory’ ) . ‘/blogroll-toggle.js’, array( ‘jquery’ ) ); } Or create a new folder in the wp-content/plugins/ folder, create a … Read more