Basic ajax call in WordPress

You have to use the admin-ajax handler to do the AJAX call. Replace file.php in var url = “file.php”; with yoursite.com/wp-admin/admin-ajax.php?action=simple_ajax And in your plugin / functions.php file, add add_action(‘wp_ajax_nopriv_simple_ajax’,’process_simple_ajax’); //for non logged in user add_action(‘wp_ajax_simple_ajax’,’process_simple_ajax’); //for nlogged in user function process_simple_ajax(){ $data = $_REQUEST; // retrieve your submitted data wp_send_json($data); // return the processed … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)