Having trouble with loading a new page on an HTML website

My website is successfully updating the database, printing all values, but for some reason the new page is not opening. The current page just keeps refreshing and I'm receiving a status of 0. Below is my code snippet:


try{
    console.log("here1 "+email);
    get1.open("GET","/Livie_project1/Check2?id="+email+"&id1="+parms["name"][0],true);
}catch(Exception ){
    console.log("error11");
}
get1.onreadystatechange = function() {
    console.log(this.readyState+" get1 "+this.status);
    if (this.readyState === 4) {
        window.open("/Livie_project1/index.html?name="+email,"_self");
        console.log("matched");
        var JSONtopicobject=eval( "("+this.responseText + ")" );
        var t=JSONtopicobject.topic.name;
        var t2=JSONtopicobject.topic.name1;
        console.log(t2+" "+t);
}};
try{
    get1.send(null);
}catch(Exception){
    console.log("erro12");
}

Even though "matched" gets printed below the window.open() function, indicating that values are being received, the new page is still not showing up. There are no errors in the console related to the page address. Could someone please point out what mistake I might be making? Any help is appreciated.

This portion relates to the servlet:


public class Check2 extends HttpServlet {
    String pwd;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {      
        String name=req.getParameter("id"); 
        String name1=req.getParameter("id1"); 
        Connection con=null;        
        Statement stmt=null;        
        PrintWriter out=res.getWriter();        

        try{
            //get a connection
            con=DriverManager.getConnection("jdbc:mysql://localhost/login","root","ATul1996@@");
            //Execute a query
            int count=0;
            stmt=con.createStatement();    
            String query ="update login set pwd="+"\""+name+"\""+" where email = "+"\""+name1+"\"" ;
            int j=stmt.executeUpdate(query);
        } catch(SQLException e) {
                out.println(e);               
        }

        res.setContentType("text/html");
        StringBuffer  returndata =new StringBuffer("{\"topic\":{");
        returndata.append("\"name\": ");
        returndata.append("\"");
        returndata.append(name);
        returndata.append("\"");
        returndata.append(",");
        returndata.append("\"name1\": ");
        returndata.append("\"");
        returndata.append(name1);
        returndata.append("\"");
        returndata.append("}}");
        res.getWriter().write(returndata.toString());
        res.getWriter().flush();
        res.getWriter().close();
    }
}

Answer №1

We have detected a mistake in your coding

  window.open("/My_project/index.html?name="+email,"_self");

The correct format should be:

  window.open("/My_project/index.html?name="+email,"_blank");

In this case, specifying "_blank" is unnecessary as it is the default setting.

If set to "_self", it will direct the URL to open in the current window.

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

Attempting to initiate an AJAX request to an API

Hey everyone, I've been working on making an AJAX API call to Giphy but I keep receiving 'undefined' as a response. Can anyone offer some advice on how to troubleshoot and fix this issue? Thanks in advance for your help! var topics = ["Drak ...

Having trouble with the rendering of the Stripe Element Quickstart example

Currently, I am diving into the world of Stripe's Element Quickstart. Take a look at this fiddle that I have been working on. It seems to be quite different from the example provided. Although I have included the file, I can't seem to figure out ...

Toggle between a list view and grid view for viewing photos in a gallery with a

Hey there, I'm a newbie on this site and still getting the hang of jQuery and JavaScript. Though I do have a good grasp on HTML and CSS. Currently, I'm working on a photo gallery webpage as part of my school project using the Shadowbox plugin. Wh ...

Is there a way for me to move a user from one room to another room?

My friend and I both have our own rooms in a session. When I want to send him a message, I need to switch his room to the same one where I am. This is the code snippet for creating my own room with static sessions: socket.on('chat-in', function ...

Preventing Event Loop Blocking in Node.js: The Key to Streamlining Performance

I am currently working on developing two APIs using Express.js. The tasks for both APIs are quite straightforward. The first API involves running a for loop from 1 to 3,000,000, while the second API simply prints a string in the console. All the necessary ...

Unknown CSS element discovered: bootstrap, gradient, carousel

I recently created a random quote app using javascript, jQuery, and bootstrap on Codepen. Everything worked perfectly there. However, when I organized the files, pushed them to git, and tried to view the app from Safari, I encountered some warnings and t ...

What could be the reason for rowsAffected not returning an integer value?

Currently, I am working on executing the SQLite statement in an iOS application. To verify the count of affected records, I have implemented success and error callback methods. Upon receiving the results, although the variables are correctly defined, I en ...

"Is it possible to keep an eye on two different events and take action once they both

I have a menu with different submenus for each list item, all utilizing the same background tag. Currently, when one submenu is open and I hover over another list item, the previous submenus hide and the new one opens. What I want is for the content to cha ...

Changing the size of shapes in cytoscape.js when using the dagre layout

My goal is to resize the shapes of the nodes based on the size of the node text. I tried following the steps outlined in https://github.com/cytoscape/cytoscape.js/issues/649, but encountered some issues: The shapes consistently end up with equal height a ...

Incorporating Vuetify into a Vue CLI application with the help of webpack

I am facing an issue with my Vue CLI application that uses Webpack and Vuetify. The Vuetify components are not loading properly, and I keep getting the following warnings: Unknown custom element: < v-app > - did you register the component correctly? ...

Implement rounded corners on D3js Donut Chart

In my AngularJS application, I have successfully implemented a donut chart as shown below: https://i.stack.imgur.com/3GVwN.png However, the design mockup indicates that we would like to achieve this look, with a border-radius property applied to the gree ...

Unattractive destructuring during conditional assignment

When working with object properties, ESLint often suggests using object destructuring. However, this can sometimes result in redundant lines of code. ESLint may not allow something like the following (which might seem like the preferable approach): const ...

Error event triggered by Ajax call despite receiving 200 ok response

$.ajax({ url: 'http://intern-dev01:50231/api/language', type: 'GET', dataType: 'json', success: function() { console.log('Success! The call is functioning.'); }, ...

Encountering an issue when attempting to construct the project: it asks for callback functions, but instead received an [

I'm currently facing an issue while trying to access a function that is crucial for updating some database values. Whenever I attempt to build the project, I encounter the following error: Error: Route.post() requires callback functions but got a [ ...

typescript library experiencing issues with invalid regex flags in javascript nodes

I am facing an issue while attempting to import a plain JavaScript module into a Node application written in TypeScript. The error below is being thrown by one of the codes in the JavaScript module. b = s.matchAll(/<FILE_INCLUDE [^>]+>/gid); Synta ...

Retrieve and utilize the dynamically produced values from the application's app.js in a script that is accessed using

In my Express.js Node web app, I generate a string in app.js during initialization: // app.js var mongourl = /* generated based on process.env.VCAP_SERVICES constant */; There is a script that I import into app.js using require(): // app.js var db = req ...

Trigger a jQuery event when a different selection is made in the dropdown menu

There are 2 choices available in the dropdown menu. <select id="_fid_140" onchange="chooseRecordPicker()" > <option value="736">9000000146</option> <option value="x3recpcker#">&lt; Browse choices... &gt;</option> Upo ...

What's the simplest method for updating a single value within a nested JSON object using TypeScript?

Using TypeScript version ^3.5.3 Consider the following JSON data: const config = { id: 1, title: "A good day", body: "Very detailed stories" publishedAt: "2021-01-20 12:21:12" } To update the title using spread synta ...

Accessing the URL causes malfunctioning of the dynamic routing in Angular 2

I am currently working on implementing dynamic routing functionality in my Angular application. So far, I have successfully achieved the following functionalities: Addition of routing to an existing angular component based on user input Removal of routin ...

Is it possible to obscure the PHP file path and conceal the parameters in a POST request?

Is there a way to securely increase the liking number on records in a database without exposing sensitive information through post requests? The PHP file and GET parameters are visible in the post request, allowing anyone viewing the page source to poten ...