Error: Attempting to use the 'append' method on an object that does not support the FormData interface

$(document).on('submit','#form_pem', function(event){
            event.preventDefault();
            var kode = $('#kode').val();
            var name = $('#name').val;
            var price = $('#price').val;
            var dataToSend = new FormData(this);

            if(kode != '' && name != '' && price != ''){
                $.ajax({
                    url:"<?=site_url('bpem/user_action')?>",
                    method:"POST",
                    data:dataToSend,
                    contentType:false,
                    proccessData:false,
                    success: function(response)
                    {
                        alert(response);
                        $('#form_pem')[0].reset();
                        $('#modalpem').modal('hide');
                        dataTable.ajax.reload();
                    }

                });

            }
            else{
                alert("Please fill in all the details!");
            }
        });

This is my JavaScript code

<div class="modal fade text-xs-left" id="modalpem" tabindex="-1" role="dialog" aria-labelledby="myModalLabel35" aria-hidden="true">
                                      <div class="modal-dialog modal-sm">
                                        <form method= "post" id="form_pem">
                                        <div class="modal-content">
                                          <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                              <span aria-hidden="true">&times;</span>
                                            </button>
                                            <h3 class="modal-title text-xs-center">Add Payment Cost</h3>
                                          </div>
                                            <div class="modal-body">
                                                <fieldset class="form-group floating-label-form-group">
                                                    <label for="Kode">Code <span class="required">*</span></label>
                                                    <input type="text" class="form-control" name="kodebayar" id="kodebayar" placeholder="Payment Code">
                                                </fieldset>
                                                <fieldset class="form-group floating-label-form-group">
                                                    <label for="name">Name <span class="required">*</span></label>
                                                    <input type="text" class="form-control" name="nama" id="nama" placeholder="Payment Name">
                                                </fieldset>
                                                <fieldset class="form-group floating-label-form-group">
                                                        <label for="projectinput7">Monthly Fee <span class="required">*</span></label>
                                                        <div class="input-group">
                                                            <span class="input-group-addon">$</span>
                                                            <input type="number" class="form-control" placeholder="Monthly Fee" aria-label="Amount (to the nearest dollar)" name="harga" id="harga">
                                                            <span class="input-group-addon">.00</span> 
                                                        </div>
                                                </fieldset>
                                            </div>
                                            <div class="modal-footer">
                                                <input type="reset" class="btn btn-grey" value="Clear">
                                                <input type="submit" class="btn btn-warning" name="action" id="action" value="Add">
                                            </div>
                                        </div>
                                        </form>
                                      </div>

                                    </div>

And this is the view. But I encountered an error like:

TypeError: 'append' called on an object that does not implement interface FormData.

Did I forget to add something? What should I do? Thank you for your assistance

Answer №1

Looking for a quick fix to correct a typo :)

proccessData:false

Change it to

processData: false

To prevent any FormData errors, ensure that the ajax options are set up like this:

$.ajax({
    url: "url",
    type: "POST",
    data: postData,
    processData: false,
    contentType: false,
    success:function(data, textStatus, jqXHR){
        //
    },
    error: function(jqXHR, textStatus, errorThrown){
        //handle errors    
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The table remains visible during an AJAX call

I need assistance with removing a table after successful deletion triggered by an AJAX to PHP call. Below is the function provided: list.php <script type="text/javascript"> function massDelete() { if (!confirm("Are you sure")) ...

Sending a JSON object with scheduled task cron job

I have a PHP cron job that is quite complex. It retrieves data from an external webpage and consolidates all the information into one variable, encoding it in JSON. Unfortunately, this entire process is slow and consumes a significant amount of time. My d ...

Sending form data using javascript without refreshing the page

I have a wall/social system similar to Facebook where users can post statuses. I want to add the functionality for users to like, dislike, and comment on a status without the page reloading. How can I achieve this with the form below? if(empty($_GET[&apos ...

Retrieve the appended element's object

I am currently facing an issue with accessing elements that are automatically added by a library in my code. In my HTML, I have the following line: <div class="bonds" id="original" style="display:block;"></div> The library appends some elemen ...

How can I retrieve the PHP response once a successful upload has occurred using DropzoneJS?

I am currently in the process of integrating Dropzone into my website. My goal is to capture the "success" event and extract specific information from the server response to add to a form on the same page as the DropZone once the upload is finished. The k ...

The use of an Authorization header is not compatible with HTTP GET requests

I recently incorporated VueSession into my project to handle user sessions. One of the components in my application is a login form that communicates with my backend (Django) to obtain a JWT token. However, I encountered an issue where although the login p ...

Encountering an infinite $digest() loop in AngularJS 1.4.8 while using ngOptions in a select when setting the model programmatically before the option is available in ngOptions

When upgrading from version 1.2.14 to 1.4.8, I encountered a problem that worked fine in the former but resulted in an infinite $digest() loop in the latter. To demonstrate this issue, you can view the following Fiddle. The Fiddle provides a clearer visual ...

Creating a Higher Order Component (HOC) for your Next.js page

Upon running the following code, I encountered an error message Error: The default export is not a React Component in page: "/" pages/index.tsx import React, { useState, useRef } from "react"; import type { NextPage } from "next&q ...

Receive suggestions through AJAX based on the input provided

Seeking to improve autocomplete functionality on my website, I aim to suggest usernames from my database as users type. The standard method involves using autocomplete's source, but with a vast number of usernames on my site, managing one large string ...

Analyzing the elements of an array in JavaScript and making modifications to it based on their values

Looking for a Solution Current Data- id price 1001 200 1001 150 1002 300 1003 50 1002 70 1004 30 Desired Outcome id price 1001 350 1002 370 1003 ...

Sending the parameter with the URL and receiving the response in return

Can the result be retrieved by calling a URL and sending specific parameters with it? For instance, if I pass two numbers along with the URL, can I receive the sum in return? The addition operation is carried out on the page being called upon. ...

What is the best way to establish a default search query within the vue-multiselect component?

I have incorporated vue-multiselect into my project. You can find more information about it here. This is a snippet of my template structure: <multiselect v-model="value" :options="options" searchable="true"></multiselect> When I open the mu ...

Using Javascript to define cookie values

I'm attempting to use JavaScript to set a cookie that will instruct Google Translate to select the language for the page. I've experimented with setting the cookie based on my browser's cookie selection of a language. <script> $(doc ...

What steps do I need to take to set up Vue-CLI 3 to generate a webpage with no JavaScript?

My dilemma is this: I have a simple static page that does not require JavaScript. Using vue-cli 3, I am attempting to pass the HTML file through webpack for minification purposes. Unfortunately, it seems that accomplishing this task is not as straightforwa ...

Improving React Efficiency: Should You Utilize Memoization of Axios GET Request Using useMemo or useCallback?

My Objective: I am currently working on a sizable function named getUnitedStatesCases, which involves making an Axios GET Request and performing various operations with the received data. I have already implemented it within a useEffect hook upon componen ...

Is it possible to use JavaScript to forcefully transition a CSS keyframe animation to its end state?

One dilemma I am facing involves CSS keyframe animations triggered by scroll behavior. When users scroll too quickly, I would like JavaScript to help send some of the animations to their 'finished/final' state, especially since the animations bui ...

Discover the optimal method of incorporating the router within CodeIgniter helper by leveraging the CI instance, for instance, employing $CI->router->fetch_method()

I am attempting to create a new method within a custom helper, but unfortunately, the code is not functioning as expected. The issue lies in being unable to access the router through the CI instance. if ( ! function_exists('active_link')) { ...

Storing the selected value of radio buttons with ajax when clicking on them

Currently, I am developing an exam system using PHP. One issue I'm facing is that when the page is refreshed, the checked radio button selection disappears. To tackle this problem, I am utilizing AJAX to save the selected option in the database every ...

What is the best way to transfer global Meteor variables to templates and effectively utilize them?

I am in the process of developing a compact, single-page application game that emulates the dynamics of the stock market. The price and behavior variables are influenced by various factors; however, at its core, there exists a finite set of universal varia ...

The dynamic concatenation of Tailwind classes is failing to have any effect, even though the full class name is being

I'm currently using Tailwind CSS within my Next.js project and I have a common method that dynamically returns the desired background color. However, despite adding the full class name, the background color is not displaying as expected. After reading ...