What is the solution for fixing the error when setting the Content-Type to "application/x-www-form-urlencoded" using xhttp.setRequestHeader()?

Despite searching extensively, I couldn't find the solution to this particular issue on Stack Overflow.

Currently, my focus is on saving a large amount of HTML data to a database using AJAX JavaScript with PHP. Below is the snippet of my JavaScript code:


function save()
{
    var hist = document.getElementById("hist").value;
    var mission = document.getElementById("mission").value;

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() 
    {
        if (this.readyState == 4 && this.status == 200 ) 
        {
            UserAccountInfo = this.responseText;
            alert(UserAccountInfo);
        }
    }
    xmlhttp.open("POST","savecompany.php",true);
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("history="+hist+"&mission="mission);   
}

The issue arises at this line of code:

xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

If I were to comment out that line, I receive the plain string in the alert and the database successfully stores the plain string.

Below is the content of my PHP file:

<?php

require "conn.php";

$history= $_POST["history"];
$mission = $_POST["mission"];

$sql = " UPDATE company SET history ='$history' , mission='$mission'  where id='1'";
mysqli_query($conn,$sql);

echo $history;
mysqli_close($conn);
?>

I'm struggling to pinpoint the error in my implementation. Any insights would be greatly appreciated.

Answer №1

It appears that you intended to input xmlhttp but instead typed xhttp. This variable is not declared.

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 width is malfunctioning on Firefox when viewed in HTML

I have been puzzled by the fact that I am unable to adjust the width of the table th in Firefox browser to the smallest value. However, in Chrome browser, this functionality works perfectly. I simply want to divide the values of my td into three rows as sh ...

Exploring an unusual HTML structure using Python's Beautiful Soup and urllib for web scraping

While extracting data may not be a challenge, the real issue lies in locating it. My focus is on scraping football data from a website that presents statistics either for all years or for specific seasons. However, despite selecting a particular season, ...

Encountering an Uncaught Error: MyModule type lacks the 'ɵmod' property

I am currently working on developing a custom module to store all my UI components. It is essential that this module is compatible with Angular 10 and above. Here is the package.json file for my library: { "name": "myLibModule", &qu ...

Developing a modification function using jQuery looping

In my quest to enhance a form I've developed, I aim to incorporate preferences. To achieve this, I have constructed an array of objects with specific fields as shown below: var userPreferences =[{ base_field:"field1", base_value:"1", preferen ...

How can I remove markers from google maps?

I have been working on a program that dynamically loads JSON data onto a map as markers when the user pans and zooms. However, I am facing an issue where I need to clear the existing markers each time the user interacts with the map in order to load new on ...

Having trouble obtaining information from the state with Pinia Store

Currently, I am delving into the world of the composition API and Pinia with Vue3. I am facing an issue while calling an external API to fetch data and store it in the state of my store. The problem arises when I try to access this state from my page - it ...

What is the best way to incorporate tailored validation into reactive forms in Angular?

I'm facing an issue with my form where I'm trying to display a specific error message based on certain conditions. Currently, my form is functioning but it's throwing a type error stating "undefined is not an object". I'm struggling to ...

Having trouble retrieving data from Redux in React

I'm struggling to load data from my state into a form. After logging in and saving the email and token into Redux state, I encounter an issue when trying to display the email within the form on a test page. Despite being able to see the email on TestP ...

Creating types for React.ComponentType<P> in Material-UI using TypeScript

I am currently working with Typescript and incorporating Material-UI into my project. I am trying to define the component type for a variable as shown below: import MoreVert from '@material-ui/icons/MoreVert' import { SvgIconProps } from '@ ...

Filter the options in the Vue Multiselect component by using the filter() method

This component and API can be found at https://github.com/vueform/multiselect Event Attributes Description @search-change query, select$ Emitted after a character is typed. I am trying to access select$.filteredOptions methods: { inputQuery( ...

Control the prompt with the Puppeteer typing function

Hello, I am currently attempting to log into a system that looks like the following: The input fields are labeled as username and password, with buttons labeled as login and cancel. I am trying to input data into these fields and click on the login ...

What's the best way to prolong the duration of a CSS animation?

I have a code snippet here that is designed to style a button when it is clicked and then maintain the style even after the click for a more aesthetically pleasing look. I'm wondering if there might be another approach to achieve this effect? Thanks! ...

Are there alternative methods for adding attributes to a component in React?

function Greeting(props) { return <h1>Greetings, {props.person}</h1>; } function Display() { return ( <div> <Greeting person="Sara" /> <Greeting person="Cahal" /> <Greeting per ...

Tabulator: the process of loading an extensive amount of data requires a significant amount of time

Currently, I am encountering an issue with loading data using a tabulator on my webpage. There are 38 tables that need to be populated, each containing approximately 2000 rows of data. The problem lies in the fact that it is taking an excessive amount of t ...

Mastering the Kendo Grid: Managing data sources for updates, creations, and deletions

Due to limitations with the MVC-wrapper of Kendo grid, I am opting to construct the Kendo grid using JavaScript instead. There are a couple of key issues when attempting to update or create records on the grid. 1-) All operations (destroy, update, create ...

Adding a PNG icon to a label in JavaScript: A step-by-step guide

How can I add a png icon alongside the label for Yourself? <div class="ui-grid-a" style="display: inline"> <label class="text-light ui-block-a">Post as: </label> <label class="link toggle-post ui-block-b" > ...

PHP for Instant NotificationsInstant notifications feature using PHP

My PHP project is facing a challenge - I need to implement real-time notifications for users, similar to the ones seen on Facebook or Google+. These notifications should display a count of new/unread notifications. In the past, my approach has been to mak ...

What's the best way to pass parameters through Higher-Order Components in React?

my custom component App import React, { Component } from "react"; import City from "./City"; import withDataLoader from "./withDataLoader"; const MyApp = () => { const MyCity = withDataLoader( City, "https://5e5cf5eb97d2ea0014796f01.mockapi ...

Step-by-step guide to dynamically load Bootstrap tab panels through tab clicks

I have implemented Bootstrap tab panels on my website, as shown below: <!-- Nav tabs --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#chartcontainer1" aria-controls="chartcontainer1" role ...

Ways to stop the click event from being triggered in JQuery

There is a single toggle switch that, when clicked, switches ON and a popup with close and OK buttons appears. However, if the toggle is clicked again, it switches OFF and disappears. The specific requirement is that with every click where the toggle switc ...