Windows location does not change after an XMLHttpRequest is made

Here is my code that uses XMLHttpRequest:

function SignUp()
{
    signUpConnection = new XMLHttpRequest();
    signUpConnection.onreadystatechange = processRegistration;
    signUpConnection.open('GET', 'index.php?registrarse=&username='+username+'&mail='+email+'&pw='+password+'&pwr='+repeatPassword, true);
    signUpConnection.send();
}

function processRegistration()
{
    var details = document.getElementById("labelUsername");

    if(signUpConnection.readyState == 4)
    {
        if((signUpConnection.responseText).indexOf("account") == -1)
        {
            window.location = "http://localhost/index.php?created";
        }
        else
        {
            details.innerHTML = signUpConnection.responseText;
        }
    }
    else
    {
        details.innerHTML = "Loading...";
    }
}

The issue I am encountering is that when a successful registration occurs (when the responseText of the XMLHttpRequest does not contain the string "account"), it does not redirect me to: "index.php?created". I have tried using assign() but it did not work either.

Answer ā„–1

I conducted a test and found that the solution works efficiently. Here is the code:

var oAjax = new XMLHttpRequest();
oAjax.open('GET', 'a', true);
oAjax.send();
oAjax.onload = function() {
  if (oAjax.status == 200) {
    window.location = 'http://baidu.com';
  }
};

Additionally, make sure to review any error messages!

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

Can a web application determine if Microsoft Excel has been installed?

Currently, I am developing a web application using ASP.NET that includes certain functionalities which rely on Microsoft Excel being installed on the user's device. In case Excel is not available, I would prefer to deactivate these features. I am foc ...

Using The Telerik AJAX radComboBox to Retrieve the SelectedValue from a Secondary comboBox

Iā€™m attempting to fill a Telerik AJAX radComboBox with the results from another. For example: comboBox1 ā€“ auto-completes and user makes a selection comboBox2 ā€“ user selects. Loads on demand. It uses the selected value from comboBox1 to populate its ...

The JSON data script is not functioning properly

Is this JSON formatted correctly? Why is it not displaying in the element with #id? I found a similar code snippet on https://www.sitepoint.com/colors-json-example/, copied and replaced the values but it's not functioning. Can anyone shed some light o ...

What steps should I take to ensure that the child menus of the v-navigation-drawer component are activated during the initial project launch?

I have created a v-navigation-drawer component with Vue 3 and Vuetify 3. The v-navigation-drawer functions properly, but I want the child menus to be visible by default without requiring the user's click when the project first launches. I am using v- ...

Improving the efficiency of my conditions in a function with Vue JS

Does anyone have any suggestions on how to optimize this function? I feel like it could be shortened to improve its efficiency. Any help or advice would be much appreciated. Function: onStudentActionSelect: function () { if (this.selectedRows.length ...

What is the reason behind my button appearing beneath my links in React?

Here is an image showcasing the current header render. The header consists of a HeaderMenu and 3 Links. While the links are functioning properly, the HeaderMenu is causing the links to be positioned below it. The HeaderMenu includes a div that wraps a Butt ...

Unlock the power of parentheses in Rails parameters in Rails 4

Utilizing AJAX to submit a form to a Ruby method has presented an issue for me. The form names are automatically generated with parentheses, and while reading the params works fine for those without parentheses, it fails for the ones with them (obviously). ...

I am having an issue with an input field not reflecting the data from the Redux state in my React app,

I am currently working on a todo list project using the MERN stack with Redux for state management. One issue I am facing is that the checkboxes for completed tasks are not reflecting the correct state from Redux when the page loads. Even though some tasks ...

Spin an object around the global axis using the tween.js library

I'm trying to achieve a gradual rotation of a cube on the world axis using tween. Initially, I was able to rotate the cube around the world axis without tweening with the following code: rotateAroundWorldAxis(cube[1], new THREE.Vector3(0,1,0),degreeT ...

Is there a way to incorporate a cancel option within my jqgrid interface?

I have a jqgrid (version 3.5.3) on my website that utilizes an ajax call to retrieve results from a web service. Sometimes, the query is complex and it takes a bit of time for the results to load. During this loading process, users see a [Loading...] messa ...

Trouble getting Fontawesome icons to accept color props when using react functional components with tailwindcss

Issue I'm Facing I'm currently working on a project that involves using icons extensively. Instead of manually adding a Fontawesome icon in every script, I have created a functional component that handles the rendering of icons based on given pr ...

Vue.js methods bound as properties on a parent object

There are times when I come across scenarios where it would be convenient to bind methods as an object property rather than a direct Vue method. For instance, instead of: <MyInput :formatter="currencyFormat" :parser="currencyParser& ...

Struggling to retrieve Ajax data and assign it to a PHP variable?

My Code Snippet is: <script> $(document).ready(function(){ $(".states").on('click','option',function(){ var selectedValue = $("select[id='stateId'] option:selected").val(); $.post('<?p ...

What is the best way to send HTML content from a controller using ajax?

Here is the code in my controller: public async Task<ActionResult> GetHtml(int id) { var myModel = await db.Models.FindAsync(id); return Json(new { jsonData = myModel.MyHtml }, JsonRequestBehavior.AllowGet); } This is ...

JavaScript CheckBox Color Change Not Functioning

Hello, I am currently experimenting with the checkAll function. When I click on the checkAll checkbox, it should select all rows and change their background color accordingly. Below is the JavaScript code I am using: function checkAll(objRef) { v ...

how to forward visitors from one URL to another in a Next.js application

I have an existing application that was initially deployed on , but now I want to change the domain to https://example.com. What is the best way to set up redirection for this domain change? I have attempted the following methods: async redirects() { r ...

Unable to transmit an object using ExpressJS

Greetings. I am currently trying to comprehend ExpressJS. My goal is to send a simple object from the express server, but it only displays "cannot get" on the screen. app.get("/", (req, res, next) => { console.log("middleware"); const error = true; ...

Is there a more streamlined approach to coding in PHP and jQuery?

My PHP script: <?php $data = file_get_contents('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml'); $xml = simplexml_load_string($data); $data1 = file_get_contents('http://www.skysports.com/rss/0,20514,11661,00.xml ...

Is this jQuery script not functioning properly?

I came across this code on jsfiddle, and I really want to incorporate it into my PHP file. However, when I tried to do so, it didn't work even though I simply copied and pasted the code without making any changes. Here is my code: <!DOCTYPE html& ...

Guide on sharing Photo Blogs on Tumblr using the "tumblr.js" NodeJS module

I've been using the tumblr.js node module to interact with the Tumblr API, but I'm having trouble understanding what exactly should be included in the "options" when posting on my blog. So far, I've only used this module to retrieve my follo ...