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

What steps should I follow to ensure that the content for the back page is printed on the back page of a booklet when using paged.js?

In the case of a booklet printed from folded sheets, it is interesting to note that the number on the back page will always be divisible by 4. If the content does not have a multiple of 4 pages, then the back page will end up inside the booklet. For my cu ...

Tips for eliminating the glowing effect when pressing down on the thumb of the material ui slider

Visit Material-UI documentation for Slider component. Despite setting the disabled flag for the entire slider, the thumb continues to show a halo effect when clicked. ...

Verify the type of email domain (personal or corporate)

Here's an example: isPersonalEmail("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0aea1ada580a7ada1a9aceea3afad">[email protected]</a>") // true isPersonalEmail("<a href="/cdn-cgi/l/email- ...

Tips for preserving updates following modifications in Angular 5/6?

I'm currently working on enhancing the account information page by implementing a feature that allows users to edit and save their details, such as their name. However, I am encountering an issue where the old name persists after making changes. Below ...

Clearing $_POST array in PHP following an ajax request made with jQuery

I am facing an issue with my JavaScript function that gathers data from input fields and checkboxes. My goal is to send this data to a PHP file and retrieve information from a database. However, I am struggling to access the POST data in PHP, so for now, I ...

Discover the power of AngularJS's ng-route feature for creating a dynamic and seamless one-page HTML template experience

I'm attempting to create a dynamic header using ng-repeat. Here's the initial code: <ul class="right"> <li><a href="#carousel">Home</a></li> <li><a href="#about-us">About Us</a></li> &l ...

What is the minimum size a string must be in order to cause the innerHTML render to be disrupted?

Can anyone tell me what the byte limit is for interrupting the rendering of an innerHTML of a DOM element when using innerHTML = $string or .append()? Is it 1MB, 5MB, 10MB? Does it vary by browser? How can I determine this limit? EDIT (11/11/11): I con ...

Problematic PHP/AJAX: How come my getAttribute function is only selecting the initial line within the foreach loop?

My goal here is to display a list of users, each with a button that sends unique IDs to the database. The issue I'm facing is that the code only works for the first user in the list and not the rest. I suspect this is because every list item has the s ...

Creating a row of aligned card components in React

Recently, I began learning React and successfully created a card component using Material UI. However, this time around, I'm attempting to create it using axios and map() methods. I expected the cards to be displayed in the same row horizontally, not ...

Protractor experiencing difficulty in adjusting price slider

As a newcomer to protractor, I am attempting to test a price slider that sorts products based on the provided price range. Unfortunately, I am facing difficulty in dragging the slider (min point) using protractor. Can anyone provide guidance on how to move ...

There seems to be an issue with the AJAX REST call failing to transmit data

Whenever I attempt to submit the form, the page refreshes and nothing gets saved in the database. The code in subforum.js $(document).on('click','#submit',function(e) { var user = JSON.parse(sessionStorage.getItem("ulogovan")); consol ...

Updating dynamic content in IBM Worklight V6.1 with jQuery Mobile v1.4.3 requires waiting for the DOM to load

I need to dynamically update the content of a div within my HTML page structure. <!DOCTYPE HTML> <html> ... <body> <div data-role="page"> <div data-role="header"> //Image </div> <!-- Th ...

Using React.js to create a modal that includes ExpansionPanelDetails with a Checkbox feature

I am trying to achieve a specific visual effect with my code. Here is an example of the effect I want: https://i.stack.imgur.com/cJIxS.png However, the result I currently get looks like this: https://i.stack.imgur.com/547ND.png In the image provided, y ...

Two values are returned from the Node.js Mongoose Exports function

Currently, I am encountering an issue with my project where a service I developed is up and running. However, it is not providing the desired value as a response. Specifically, the goal is to generate coffee items linked to specific companies. Whenever new ...

"Enhancing security measures with multiple nonce for Content Security Policy

I am encountering an issue with my single page application, which is developed in .net core MVC 2.2. The application loads html sections on the fly. In the main document, I have added a Content Security Policy (CSP) policy with a dynamically generated hea ...

Trouble arises when displaying data using AngularJS in an HTML environment

I'm currently facing a challenge understanding where I went wrong in my code. My goal is to display the initial array values in the table data, but so far, I haven't had much success. Here is the HTML section of the code; <body ng-controller ...

Refresh the page with user input after a button is clicked without reloading the entire page, using Python Flask

My python/flask web page accepts user input and returns it back to the user without reloading the page. Instead of using a POST request, I have implemented Ajax/JavaScript to handle user input, process it through flask in python, and display the result to ...

Angular 5: There was an issue with the property not defined for lowercase conversion

I keep encountering this error whenever I attempt to filter a column of a table. The data is retrieved from a FireStore cloud collection and the 'auteur' field is defined in each document. Here is how my component looks: import { Component, OnI ...

Transforming vanilla JavaScript into jQuery

Is there a more efficient way to write this code using jQuery? It's functioning properly in Firefox but not in Safari or Chrome without any error messages, making it difficult for me to troubleshoot. Any suggestions or insights would be greatly appre ...