No response received from the server

I recently encountered an issue with an ajax call that updates my database. While the call successfully goes out and updates the database, I do not receive any response back from the server. I have confirmed this using firebug, noticing that there is a post tab but no response tab as usual.

Below, you will find the code snippet that I have been working on. Any insights or assistance would be greatly appreciated.

function addCourse()
    {

    var memid = document.forms["addCoursesForm"]["Member"].value;
    var CourseName = document.forms["addCoursesForm"]["CourseNames"].value;
    var CourseDate = document.forms["addCoursesForm"]["Cdate"].value;
    var CourseExpiry = document.forms["addCoursesForm"]["Edate"].value;

    if(window.XMLHttpRequest)
        {
        xmlhttp=new XMLHttpRequest();
        }
    else
        {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyStat==4 && xmlhttp.status==200)
            {
            document.getElementById("ConfirmCourse").innerHTML=xmlhttp.responseText;
            }
        }
    xmlhttp.open("POST", "addCourseDB.php");
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send("memid="+ memid+ "&CourseName="+ CourseName+ "&CourseDate=" + CourseDate+"&CourseExpiry="+ CourseExpiry);

Answer №1

If I were to make a change, it would be adjusting this particular line:

xmlhttp.open("POST", "addCourseDB.php");

to:

xmlhttp.open("POST", "addCourseDB.php",true);

By doing so, the onreadystatechange function will be properly handled for the event (asynchronous event).

Alternatively, considering using jQuery could simplify this process of handling xmlhttp requests.

UPDATE: For further information, you can refer to this reliable source: http://www.w3.org/TR/XMLHttpRequest/#the-open-method

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

Issue with Jquery form plugin functionality on Internet Explorer 8

After spending 4 hours trying to figure out this problem.... I have a plugin that uploads photos and returns them to the Tinymce Editor. It works perfectly in Chrome and Firefox, but for some reason, it fails in IE. When I check the developer tools, I see ...

Ways to automatically display the date upon loading the view

I have integrated a plugin with Angular, which is essentially an extension. Upon loading the view, only an empty input is visible. Clicking on the input reveals a calendar with today's date displayed. My objective is to automatically load today&apos ...

Convert individual packages within the node_modules directory to ES5 syntax

I am currently working on an Angular 12 project that needs to be compatible with Internet Explorer. Some of the dependencies in my node_modules folder are non es5. As far as I know, tsc does not affect node_modules and starts evaluating from the main opti ...

What is the fastest and most efficient method to confirm that all rows in a 2D array are of equal length?

Imagine you have a 2D array like this: const matrixRegular = [ ['a', 'b', 'c'], ['e', 'f', 'g'], ]; Now, let's think about how we can check if every row in this matrix has the same ...

Vuejs is throwing an error claiming that a property is undefined, even though the

I have created a Vue component that displays server connection data in a simple format: <template> <div class="container"> <div class="row"> <div class="col-xs-12"> <div class="page-header"> < ...

Error: The texture is not rendering on the object in Forge Three.js

I am struggling to showcase a textured plane using Three.js within the context of Forge RCDB. Initially, I was able to render the plane; however, it appeared completely black instead of being textured... After making some adjustments, now nothing is showin ...

What is the best way to retrieve the name/value pairs from a JSON object

function (data) { //add values based on activity type //data = JSON.parse(data); //alert(abc.Phone1); alert(data.myName) alert(data.toString()); if (activityType == "Phone") { } return; }, By observing the callback funct ...

"Combine JSON data using an observable based on the ID field

Consider two distinct REST services in my project: todo.service.ts user.service.ts Below are the properties defining each object: todo: userId, title, id, completed user: id, name, email, etc Both services return an Observable with collections conformi ...

How come my Django application is returning an empty response when using jQuery.ajax?

Trying to send a JSON response from a Django view using an ajax call: var tab = 'example'; var response = $.ajax({ url: "/" + tab + "/" }).responseText; alert(response); This is my Django view code: If request.is_ajax() == True: req = ...

Using React-router-dom's Link component will update the URL without actually loading a new component

I've been having trouble setting up nested routes with React Router. I put together a small example of what's not working here: https://codesandbox.io/s/silly-dubinsky-of2mu Essentially, I have two routes with a sub-route each: first/first and ...

Both position absolute and position relative are failing to work effectively

Whenever I click on a div called "test", another div named "outside" appears, along with a div named "inside" that has a higher z-index. The problem arises when I try to set the position of "inside" to absolute, as I am unable to assign a margin-bottom. A ...

Exploring arrays and objects in handlebars: A closer look at iteration

Database Schema Setup var ItemSchema = mongoose.Schema({ username: { type: String, index: true }, path: { type: String }, originalname: { type: String } }); var Item = module.exports = mongoose.model('Item',ItemSchema, 'itemi ...

Send information to a Django view using AJAX

I'm just dipping my toes into the world of django and exploring jquery, ajax, and more. In one of my pages, I trigger a function (using javascript and jquery) that utilizes the POST method to send data to my django view. Here's my jquery functi ...

Alert: Parser error in JSONP!

$.ajax({ type: "GET", dataType: "jsonp", jsonpCallback: "jsoncallback", //async: true , data: { // some other data here }, url: "http://mywebsite.com/getRequest.php", success: function(response ...

Determine if the object's value is present

My current JavaScript setup looks like this: var NAMES = []; function INFO(id,first,middle,last){ var newMap = {}; newMap[id] = [first, middle, last]; return newMap ; } Next, I have the following code block: for (var j = 0; j < NUMBER.leng ...

Issues with uploading files on iOS devices when using ReactJS

Encountering an issue with uploading photos on iPhone in a Reactjs app. The problem seems to be specific to iOS as the code works fine on Android and computer. Below are the codes for better debugging. "use client" import Link from "next/l ...

Using AngularJS to incorporate ng-include with ng-click functionality

I am trying to figure out a way to insert HTML that is specifically optimized for the controller into an alert div. Unfortunately, I have been unsuccessful so far... <script type="text/ng-include" id="login.html"> <form data-select="exepti ...

When the "/" button is clicked, display a menu and highlight the menu choices for selection

I have been working on developing a similar concept to Notion, and I am facing a challenge with a specific feature. I want a menu to appear when the user clicks "/", providing options to change the current block to their preferred style. Currently, I can c ...

I am unable to store a session variable using the GET method

Good day, I am seeking assistance with my code and have been searching for four hours without finding the error. I am working on an exchange where variables are stored in a session. The issue I am facing is that the variable $discount gets cleared every ti ...

Hide the search results if the user leaves the input field blank

I am trying to implement Live Search JSON Data Using Ajax jQuery, and I want to be able to search through multiple JSON files. When the page initially loads with an empty input field, no results are displayed. However, if you type and then delete text in ...