transmitting various information through ajax post technique in jsp

function checkXmlHttpRequest()
{
    var xmlHttp = false;

    if (window.XMLHttpRequest)
    {
        return new XMLHttpRequest(); //To support the browsers IE7+, Firefox, Chrome, Opera, Safari
    }
    else if(window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP"); // For the browsers IE6, IE5 
    }
    else
    {
        alert("Error due to old verion of browser upgrade your browser");
    }
}

var xhr = new checkXmlHttpRequest(); //xhr holds the ajax object

function postToServlet()
{
    if(xhr)    
    { 

        var company_to = document.getElementById("comp_to").value;
        var subject = document.getElementById("comp_subject").value;       
        var complaint = document.getElementById("comp_letter").value;        
        var dateTime = document.getElementById("date_time").value;

        if(company_to==""||subject==""||complaint==""||dateTime=="")    
        {     
            document.getElementById("redSignal").style.display='block';    
            document.getElementById("redSignal").innerHTML="All Fields are necessary";     
        }    
        else    
        {    
            xhr.open("POST","complaintHandler",true);    
            xhr.onreadystatechange = handlePostToServlet;    
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

            var dataString="to="+company_to+"&subject="+subject+"&complaint="+complaint+"&dateTime="+dateTime;    
            xhr.send(dataString);     
        }    
    }
}

function handlePostToServlet() 
{
    if (xhr.readyState == 4) 
    {
        if(xhr.status == 200)
        {
            document.getElementById("greenSignal").style.display='block';
            document.getElementById("greenSignal").innerHTML=xhr.responseText; 
        }
        else 
        {
            document.getElementById("redSignal").style.display='block';
            document.getElementById("redSignal").innerHTML="Error Code ="+xhr.status; 
        }
    }
}

I am encountering an issue with error code 404 What could be causing this problem in the code? Any assistance is appreciated.

Answer №1

When encountering Error 404, it indicates that the URL you are trying to access is incorrect.

 xmlhttp.open("POST","complaintHandler-wrong",true);

Make sure to verify the correctness of this URL first.

Answer №2

ERROR 404 indicates that the requested HTTP request is either missing or incorrect.

Make sure to double-check your "complaintHandler". It could possibly be complaintHandler.jsp, among other things...

For further reference, please take a look at this tutorial.

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

In what way can I ensure that the value of currentIndex is consistently set to 0 before each calculation?

Is there a way to set the Value of currentIndex to always be 0? The calculation of (CRANK1 + CRANK2) + (DRANK1 + DRANK2) should result in (0 + selected amount), but it is currently calculating as (selected amount + selected amount). Any assistance would ...

Having difficulty customizing the layout with JavaScript

I want to demonstrate the ability to send a message without hardcoding all messages in my frontend. I utilized existing code from this link shared by another developer. I have included the id="msg" in the input field and id="chatpanel" with class chat-pan ...

Is it possible to access a local excel file by using a file URL that contains a space within it?

Issue: I'm encountering difficulty opening a local Excel file via a file URL when the directory containing the file has spaces in its name. In my scenario, I have an HTML file with a link that should open a local Excel file from the same directory. T ...

Tips and tricks for displaying a confirmation modal prior to a user switching to another tab

In my application, I have a section designed with Bootstrap 4 tabs. There are six tabs, and five of them contain forms with input fields. The original code was submitting all data (for all 5 out of 6 tabs) at once. This approach seemed unnecessary to me si ...

The menu starts off in the open position when the page loads, but it should remain closed until it

I'm having trouble with my menu; it displays when the page loads but I want it to be closed and then open when clicked. Despite my best efforts, I can't seem to fix this issue. <html> <head> <script> $(document).ready(funct ...

Leverage a single JavaScript file across all Vue components without the need for individual imports

My project includes a JavaScript file called Constant.js that stores all API names. //Constant.js export default { api1: 'api1', api2: 'api2', ... ... ... } Is there a way to utilize this file without having to impo ...

Post-load process of jQuery AJAX tabs

Situation In my webpage, I am using tabs that utilize AJAX to load content. However, the response from the server is not just the HTML to be displayed. To set up the tabs, I am using the code snippet below and prefer to keep the processing in this locati ...

When dealing with a large number of records, the performance of querying with MongoDB in a Meteor.js application may decrease due to the high volume

I have a project in meteor js with a large amount of data stored in a mongodb database, currently around 50,000 messages. I am facing issues with the performance of my application as it is taking too long to render or load the data from the database. Addit ...

The translateX property will be set to the offsetX value of the event when the mouse is moved, resulting in a

Here's a quick and easy question regarding some kind of scrubber tool. Check out the fiddle below. When using jQuery to bind to the mousemove event and adjusting the transformX property in the positive direction, there's a 50% chance it will ret ...

Create a collection of data by retrieving values from a web service response

My goal is to populate table values from a webservice response. The issue arises when the response format is not compatible with the table. The response structure may vary. 0:{name: "image.png", base64: "iVBORw"} 1:{name: "download.png", base64: "iVBO"} 2 ...

Submission form triggered with incomplete or inaccurate data

I am struggling with preventing my form from submitting if the user has not entered information or has entered it incorrectly. Despite having code in my JavaScript to handle this validation, when I click the submit button, the form still submits. I tried u ...

Live search with AJAX, navigate to a different page, and showcase the findings

I currently have multiple web pages that all feature the same search form. What I want to achieve is for the results page to load dynamically as the user starts typing, replacing the current page and displaying all relevant items found. How can I implement ...

Tips for using JSON.stringify in a secure manner

After receiving a JSON object, I convert it to a variable called embed. The console.log output is: console.log(send_me_along) {"provider_url":"https://www.site.com/","description":"Stuff, you’ll need to blah blah","title":"Person detail view & ...

Is jQuery's $.ajax causing a memory leak?

What is causing the memory leak in browsers like Firefox when using jQuery ajax? Check out this jsfiddle: http://jsfiddle.net/Rqfz7/ Many users have reported that running this code in Firefox causes a significant increase in memory usage. Have you experi ...

How can objects be merged within an array and a new object be inserted?

I have an array of objects representing podcasts in a podcast app. Here is how the data looks: [{ id: "uuid-1" timeInSeconds: 1000 dateListened: "2021-01-01T15:57:17.000Z" }, // <---same day { id: "uuid-2" timeInS ...

Ways to verify whether a Discord bot has been authenticated through the Discord Bot Verification process

Is it possible to check if a Discord bot has a Verified check mark using Discord.js? https://i.sstatic.net/qyHjG.png I'm looking for ways to prevent raids or nuke bots client.on('guildMemberAdd', member => { if (member.user.bot) { ...

Tips for sending a variable from Javascript to node.js, specifically connecting to MYSQL

Can you help me with a simple example on how to pass a variable from JavaScript to Node.js? I need to store the user input from a text box in Node.js and perform some actions. Client <!DOCTYPE html> <html> <body> <h2>HTML Forms< ...

Differences Between JavaScript Binding and Anonymous Functions

I came across this code in the mongoose-deep-populate library async.parallel([ User.create.bind(User, {_id: 1, manager: 2, mainPage: 1}), Comment.create.bind(Comment, {_id: 3, user: 1}), ... ], cb) which utilizes Function.prototype.bind to make ...

The Complex World of JavaScript Variable Mutation

Currently, I have a loop in my code that checks the id of the last div on the page and uses AJAX to replace it with an updated div. However, if the loop runs again and the id remains the same, it just adds another duplicate of the updated div. My goal is ...

What is the best way to create a promise in a basic redux action creator?

My function add does not return any promises to the caller. Here's an example: let add = (foo) => {this.props.save(foo)}; In another part of my application, I want to wait for add() to finish before moving on to something else. However, I know t ...