Title: jquery to es6 javascript ??
Last modified: February 11, 2024

---

# jquery to es6 javascript ??

 *  [roelof](https://wordpress.org/support/users/roelof/)
 * (@roelof)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/jquery-to-es6-javascript/)
 * Hello,
 * 
   I found this snippet in a tutorial about submitting a form. `    $.ajax({url:
   submitUrl,type:'post',data:fd,contentType:false,processData:false,success:function(
   response){ callback(response); },});`
 * but I wonder if and how this could be writtten as “normal” js es6 code. 
   I like
   es6 code more then jquery code.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/jquery-to-es6-javascript/#post-17416619)
 * What you do depends on what you want as a response from WP. If the form’s Ajax
   handler is already in place and you merely want to submit with ES6 instead of
   jQuery, that’s fine. Be sure the form data includes an “action” value (usually
   as a hidden field). Ajax data is normally submitted to /wp-admin/admin-ajax.php.
   What you get back as a response varies greatly by what Ajax handler code is in
   place server side.
 * PHP is kind of finicky about what sort of data stream is acceptable. For jQuery.
   ajax(), specifying `dataType : 'json',` works for me. I suggest whatever the 
   ES6 equivalent is should suffice.
 * Disclaimer: As you might suspect from that last line, I don’t know ES6 very well.
   But as long as admin-ajax.php receives properly formatted data, it doesn’t matter
   what language sent the request.
 *  Thread Starter [roelof](https://wordpress.org/support/users/roelof/)
 * (@roelof)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/jquery-to-es6-javascript/#post-17416632)
 * oke, 
   Then maybe look at the jquery how i can dynamically make a div for the 
   errors or the success box. I know how to do that with plain js but not with jquery
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/jquery-to-es6-javascript/#post-17419644)
 * Why not use the language you’re comfortable with? WP doesn’t care what sent the
   data.
 * If you want to stick with jQuery to broaden your coding experience, when you 
   enqueue your jQuery code, be sure to specify `'jquery'` as a dependency so that
   the jQuery library gets loaded. The jQuery used by WP runs in “noConflict” mode,
   meaning the common `$` shortcut will not work. Either use the full `jQuery` or
   place your code within a “noConflict” wrapper. For example:
 *     ```
       (function( $ ) {
   
       	"use strict";
   
       	// javascript code here. i.e.: $(document).ready( function(){} ); 
   
       })(jQuery);
       ```
   
 * While it’s possible to add divs for success or error, usually these already exist
   on the page, but they are initially empty. The success or error processes then
   simply populate the div content as appropriate. It’s easier to populate an existing
   empty div than to insert a new one. For example, the error: process of .ajax()
   could do:
    `$("#error-div").html("Sorry, that didn't work");`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘jquery to es6 javascript ??’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/jquery-to-es6-javascript/#post-17419644)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
