How to do the simplest possible frontend ajax call from a plugin?

I’m trying to make this as simple as possible just to get the basics down, but I keep getting a 400 error and 0 response from admin-ajax.php. I just want to hit ajax with some data. Here’s my js:

jQuery(document).ready(function($  ) {   $  ('body').click(function(e){       $  .ajax({           action: 'the_ajax_hook',           data: 'field=data',           type: 'post',           url: the_ajax_script.ajaxurl,           success: function(response_from_the_action_function) {               $  ("#site-content").html(response_from_the_action_function);           }       });   }); }); 

And here’s my plugin:

function load_my_scripts(){      wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( __FILE__ ) . 'ajax.js', array( 'jquery' ) );      wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); }  add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); add_action( 'wp_ajax_the_ajax_hook', 'the_action_function' ); add_action( 'wp_ajax_nopriv_the_ajax_hook', 'the_action_function' );   function the_action_function(){   echo "field is " . $  _POST['field'];   die(); } 

The localization seems to work because it hits the right URL for admin_ajax, but it’s a bad request and returns nothing.

I know I’m missing something obvious but that’s the thing about obvious mistakes, they don’t seem obvious until someone else shows it to you. What am I missing?

replace featured image from frontend

I need to replace the featured image of a post in the frontend. I’am using this code without success:

<form id="featured_upload" method="post" action="#" enctype="multipart/form-data">     <input type="file" name="my_image_upload" id="my_image_upload"  multiple="false" />     <input type="hidden" name="post_id" id="post_id" value="55" />     <?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>     <input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload" /> </form>        <?php  if (      isset( $  _POST['my_image_upload_nonce'], $  _POST['post_id'] )      && wp_verify_nonce( $  _POST['my_image_upload_nonce'], 'my_image_upload' )     && current_user_can( 'manage_options', $  _POST['post_id'] ) ) {      include('wp-admin/includes/image.php' );     include('wp-admin/includes/file.php' );     include('wp-admin/includes/media.php' );      if (has_post_thumbnail( $  _POST['post_id'] )) {     $  featured_image = wp_get_attachment_image_src(get_post_thumbnail_id( $  post->ID ), 'full' );     }     $  attachment_id = media_handle_upload( 'my_image_upload', $  _POST['post_id'] ); 

What am’I missing?

JavaScript and JQuery ยท Interactive Front-End Web Development for $10

Learn JavaScript and jQuery a nicer way This full-color book adopts a visual approach to teaching JavaScript & jQuery, showing you how to make web pages more interactive and interfaces more intuitive through the use of inspiring code examples, infographics, and photography. The content assumes no previous programming experience, other than knowing how to create a basic web page in HTML & CSS. You’ll learn how to achieve techniques seen on many popular websites (such as adding animation, tabbed panels, content sliders, form validation, interactive galleries, and sorting data).. * Introduces core programming concepts in JavaScript and jQuery * Uses clear descriptions, inspiring examples, and easy-to-follow diagrams * Teaches you how to create scripts from scratch, and understand the thousands of JavaScripts, JavaScript APIs, and jQuery plugins that are available on the web * Demonstrates the latest practices in progressive enhancement, cross-browser compatibility, and when you may be better off using CSS3 If you’re looking to create more enriching web experiences and express your creativity through code, then this is the book for you.

by: Deshx
Created: —
Category: Programming
Viewed: 250


Front-end website development / bug fix

I'm a freelance front-end developer and specialize in the conversion of Photoshop and Sketch files to cross-browser compatible, fully responsive website. I have been having 11 years of experience since 2008, including 1 year of experience working for a web development company.

Currently I'm providing front-end development service. The rate and the turnaround time depend on the scale and the complexity of the design. A short page like…

Front-end website development / bug fix

Frontend / Backend Development, Bug Fixes – 11 Years on DP!

Well Known Freelance Developer here back to offer all services to DP Forums, I have been a member of DP and offering my Services in good standing for 11+ years.

I am a Frontend/Backend Developer and have worked on and completed many projects including Crypto-Related. There are no limits to my skills; if it can be made I can make it.

The main programming languages I work with are PHP & Mysql, HTML, CSS, Javascript, JQuery, Ajax.

If there is something that you are looking to have…​

Frontend / Backend Development, Bug Fixes – 11 Years on DP!

What is the name of the widget that is used for showing tutorials about a frontend app

There are some sites I’ve been on where, the first time you visit it, it will show you a little tutorial.

The tutorial will have big round animations that encircle a button and say something like “Click this button to add an item to your shopping cart!” and then you click Next and another button is highlighted, etc.

Is there an official name for this widget, or behaviour? I remember seeing a widget framework like “material-ui” contain aa widget like this but I don’t remember…

Laravel PHP & Front-end Developer. for $30

I can develop any customized and fully responsive web application using laravel & php. Further more, I can solve any issue, add new features to existing site. Services: php, laravel issueHtml, css & javascript issuepayment gateway integrationAdmin panelLaravel cms developmentDatabase (MySQL)Email integrationapi integrationLaravel custom site Packages: Responsive.Custom design.Optimized Images for Fast-Load.SEO Friendly design.Time is money. I will plan the price package according to your requirement.Cross-Browser Compatible! (Firefox, Chrome, Safari, Opera)100% satisfaction.30 Days free technical support.Rush Delivery within 4 days at extra cost.Revisions until client satisfaction. Expertise: HTMLCSSBootstrap 4JavaScriptMySQL Database.Laravel Framework PhpReact.js Kindly contact me before placing the order. Thanks.

by: arslnwaz
Created: —
Category: PHP
Viewed: 6


Woocommerce – Order info is empty on frontend?

I’m trying to create a page similar to the checkout page with all the customer, billing, and order information. As a last resort, I tried to retrieve the unique order link, but I had trouble with even that.

This is my current code, and the array shows up with empty fields.

<?php $  order = new WC_Order( $  order_id ); $  items = $  order->get_items(); foreach ( $  items as $  item ) {     $  product_name = $  item['name'];     $  product_id = $  item['product_id'];     $  product_variation_id = $  item['variation_id']; }  print_r($  order) ?> 

Empty array