Cannot access elements of json object

The result that is currently returned is raw text, which means data[0] accesses the first element (i.e. character) of the string, which is {. Obviously, you want to turn the returned data into a JSON object. To do this, jQuery.ajax() has a nifty property called dataType, which determines the way jQuery interprets the data returned … Read more

Registration e-mail check with AJAX

You have missed few things in your ajax. Please find following updated code which will help you to solve your problem function add_ajaxurl_cdata_to_front(){ ?> <script type=”text/javascript”> //<![CDATA[ ajaxurl=”<?php echo admin_url( “admin-ajax.php’ ); ?>’; //]]> </script> <?php } add_action( ‘wp_head’, ‘add_ajaxurl_cdata_to_front’, 1); add_action( ‘wp_footer’, ‘add_js_to_wp_footer’ ); function add_js_to_wp_footer(){ ?> <script type=”text/javascript”> jQuery(‘document’).ready(function(){ jQuery(‘#reg_email’).on(“change”,function(){ jQuery.ajax({ type: ‘POST’, … Read more

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

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

Creating custom AJAX requests

In WordPress the way of handling Ajax calls is a bit different the plain PHP but still very simple, all ajax calls should be to wp-admin/admin-ajax.php and you just define your own functions by hooks, Take a look at What’s the preferred method of writing AJAX in WordPress