issue with a xmlhttp request

A JavaScript function using xmlhttp is shown below:


var params = "a=" + encodeURIComponent(a) 
           + "&b=" + encodeURIComponent(b)
           + "&c=" + encodeURIComponent(c);
var url = "noob.php";

xmlHttp2.open("POST", url, true);

xmlHttp2.onreadystatechange = stateChanged2;
xmlHttp2.send(params);

Here is the code for noob.php:


<?php

include('config.inc.php');
include('database.inc.php');
$a = mysql_real_escape_string($_POST['a'], $con); 
$b = mysql_real_escape_string($_POST['b'], $con); 
$c = mysql_real_escape_string($_POST['c'], $con);

mysql_query("INSERT INTO users (inchat,preference) values('N','$a$b$c');");

echo mysql_insert_id();

mysql_close($con);

?>

I have tested all the code of noob.php with a html form and it works fine. The issue may be related to:


xmlHttp2.onreadystatechange = stateChanged2;
xmlHttp2.send(params);
  1. The parameter sending process failed, unfortunately I am not sure how to test this

  2. The string sent might not be recognized by noob.php due to possible formatting issues

The problem arises from the fact that the parameter is not being inserted into the table. So which of the above possibilities could be the cause?

Answer №1

The functionality of the code in noob.php is fully operational, as tested with an HTML form. Therefore, any potential errors likely stem from:

xmlHttp2.onreadystatechange = stateChanged2; 
xmlHttp2.send(params);

Issues like this can often be easily pinpointed by inserting an alert after a suspicious line.

If you encounter uncertainty regarding xmlHttp2.send(params);, start by placing an alert after

xmlHttp2.onreadystatechange = stateChanged2;
. If the alert does not appear, investigate the function stateChanged2; where it is defined, as that is most likely where the error lies;

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

Replace a portion of text with a RxJS countdown timer

I am currently working on integrating a countdown timer using rxjs in my angular 12 project. Here is what I have in my typescript file: let timeLeft$ = interval(1000).pipe( map(x => this.calcTimeDiff(orderCutOffTime)), shareReplay(1) ); The calcTim ...

Forward to the login page when an ajax request is made

In my project, I have implemented two methods for authentication: form_login and Cas with a single Provider (user). I have configured the login form in security.yml and created a Guard for Cas. After extensive testing, I successfully integrated both authen ...

Issue with injecting Angular service in unit test

Hello, I'm currently working on a simple test: define(["angular", "angularMocks", "app", "normalizer"], function(angular, mocks, app) { describe("service: normalizer", function () { var normalizerService; beforeEach(module("ADB")); b ...

I'm sorry, but we were unable to locate the module: Error: Unable to find 'fs' in '/usr/src/app/node_modules/jpeg-exif/lib'

Encountering an error when building a react app on production: Module not found: Error: Can't resolve 'fs' in '/usr/src/app/node_modules/jpeg-exif/lib' Node Version: Node version 18 Steps taken in Docker Production: npm install - ...

The image is currently not being displayed

I am experiencing an issue where the image is not showing up on my HTML page. The Image Path values are correct and there are no errors in the code. What could be causing this problem? import React from 'react'; import {Wrapper, Title} from &apos ...

Blur Event Triggered in Primefaces Editor

My current setup involves using JSF Mojarra 2.2.8 with PrimeFaces 5.1, where I utilize a PrimeFaces editor for text input. I am looking to automatically upload the entered text via ajax. However, the editor only supports an onchange event. I'm seekin ...

Implement Vue.js functionality to dynamically add the 'active' class upon clicking an element, while also removing

Is it possible to create an active link on a div element? Check out this example to see how you can achieve that in your code: http://jsfiddle.net/fiddleyetu/9ff79/ $(function() { $( 'ul.nav li' ).on( 'click', function() { $ ...

Is it possible to utilize filter in place of forEach in Javascript?

Is there a way to refactor the function below that currently uses forEach to instead use filter? I've searched online but couldn't find a suitable solution. pendingPaymentsUtils.getPendingPayment = paymentId => { const payments = pendingPay ...

Tips on how to showcase various information in distinct tabs using VueJS

I am currently working on a website project utilizing the VueJS framework and Vuetify template. My goal is to showcase different content under separate tabs, however, I'm encountering an issue where the same content is being displayed in all three tab ...

Creating a decorative ribbon in three.js for your gift presentation

How can I create a ribbon for a gift box using three.js, similar to the example shown here: Is it possible to create the ribbon with just one piece or do I need multiple pieces to achieve the desired look? Thank you :) ...

There seems to be an issue with the CSS file linking properly within an Express application

Every time I run my app.js file, the index.html file is displayed. However, when I inspect the page, I notice that the CSS changes are not taking effect. Strangely, if I open the HTML file using a live server, the CSS changes are visible. Can someone exp ...

javascript code for subtracting values in arrays

I am facing a scenario where I have 3 arrays of the same length. My requirement is to automatically subtract the values in the first two arrays without any user input. If the result of subtraction is negative, I need to identify the index of that array num ...

Creating an adaptable grid system in Vue Material

I am working on a project where I am using Vue-Material to display user-inputted cards in a grid layout. While the cards are rendering correctly, I want to optimize the grid to make it flexible, justify the cards, and stagger them in a way that eliminates ...

"Use jQuery to select all the cells in a row except for the

I found a visually appealing table layout that looks like this : https://i.stack.imgur.com/oRxYP.png What caught my attention is how clicking on a row selects the entire row. Take the example in the image above, where the second row is highlighted upon s ...

What is the best way to incorporate polling into the code provided below? I specifically need to retrieve data from the given URL every 60 seconds. How should I go about achieving this

Can you assist me in integrating polling into the code below? <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"> ...

Using JSON to create bootstrap styled link buttons

My current code is functioning well with links. However, when I try to use a bootstrap button instead of a regular button, the button appears in the table but no longer directs to the link. var button = "<button class='btn btn-inf ...

Issue encountered while utilizing PHP sessions

I'm currently developing a basic login page that utilizes JS, JQuery, and PHP. login.php <!DOCTYPE html> <head> <title>AJAX Login Learning Activity</title> <link rel="stylesheet" type="text/css" href="login.css"> ...

Save all dynamically received data from a form in PHP as an array

I have developed a PHP form that dynamically adds new text variables in this manner: <form action="" enctype=”multipart/form-data” method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>"> <div id="div"> va ...

changing button text in ajax upon successful completion

I am looking to update the button text upon successful completion. Specifically, I would like to change it to "accepted" after a successful response. <button type="button" onclick="saveData<?php echo $row1->id; ?>()">Accept</button> ...

retrieving a cryptic assortment from a document with the help of ajax

I attempted to retrieve an encoded array [{"got":"1235.00","needed":"4350"}] from a file using the following code: function getNewValues(){ $.ajax({ dataType: 'json', url: 'get.php', type: &ap ...