The URL provided for the Ajax HTTP request is not accurate

Consider the following JavaScript code:

<script type="text/javascript" charset="utf-8>      
    function goForLogin() {
        var xmlhttp;
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("POST","/account/login",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("email=test%40test.com&password=1");
            }
</script>

I am required to run this code in module test/index.

Upon logging the request with tampadata, I noticed that the URL is

http://dev.server.com/test/account/login
. How can I remove test from the URL as it should be directed to a different module?

If I change the url to dev.server.com/account/login/ in the xmlhttp.open function, the resulting output will be:

http://dev.server.com/test/dev.server.com/account/login/
.

Answer №1

Make sure to provide the complete URL for your POST request destination:

https://example.server.com/user/login

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

Is there a way to determine the quantity of child objects and transmit the calculated index to each individual child object?

My data is structured as shown below: team1 : { author92 : "John" , author43 : "Smith" }, team2 : { author33 : "Dolly", author23 : "Mark" }, I want to display Authors grouped together with an ad ...

Converting a date from PHP to JavaScript

My PHP code generates the following date: <?php date_default_timezone_set('Europe/London'); echo date('D M d Y H:i:s O'); ?> Additionally, I have a JavaScript/jQuery script that displays this date on the website: setInterval( ...

Performing a jQuery GET request using an AJAX call to retrieve data from

I have a situation where I am using jQuery's $.get() method to fetch data from an external PHP file. The issue I am facing is that when refreshing two external files, the HTML for the second file (messages.php) refreshes and then refreshes again 300ms ...

I am looking for a way to add some color to the text within a div on my HTML page. Can you help me

Is there a way to apply background color only to the text content within this div, without styling the entire element? ...

Is it possible to utilize curly brackets in JavaScript for dividing code segments?

Check out this code snippet. I'm curious if there are any potential drawbacks to using it. //some example code var x = "hello"; { var y = "nice"; function myfunction() { //perform tasks... } } One advantage I see in utilizing t ...

Enter the Kannada language into the HTML text box or input field

My html form consists of about 15 - 20 input and textarea fields. As a user, how can I enter information in Kannda or any other local language? https://i.stack.imgur.com/60PVT.png ...

Display message in a modal using React or JavaScript

Here's a puzzling query I have: Users can upload .MSG files to our system, and the BASE64 data is stored in the database. Now, I'm trying to incorporate these .MSG files into a model but facing conversion issues with BASE64 data. Interestingly, I ...

Safari experiencing hang after successful CORS OPTIONS request

Safari (10 - OSX El Capitan) Issue with CORS Encountering a problem with CORS while performing a POST request from an AngularJS front-end to a Laravel back-end. In Chrome and Firefox, both OPTIONS and POST requests return http status 200 OK In Safari 10 ...

"message": "Please provide a valid user path.",

When attempting to store the user in the database, the response indicates that the "user" path is required even though the user value is present in req.body and logged for verification purposes. However, the issue persists with storing it in the database. ...

What is the process for updating parameters before finalizing a route in Vue.js?

I have set up a route with a value parameter: routes.push({ name: 'test', path: '/test/:value', component: resolve(__dirname, 'src/pages/test.vue'), }); Now, I want to modify the route so that it also include ...

Synchronizing the call of various views in an Angular application

I'm currently working on an angular single page application with a specific structure in mind. "app.parent - main parent state" "app.parent.childState - child state" "app.parent.childSatate" includes 4 different named views. My goal is to display so ...

Loading a PDF file in a dynamic manner

I'm having trouble with the syntax for passing PDF data received from an AJAX request and updating an object with the PDF data. I'm attempting to implement a progress meter / please wait mechanism while the PDF is being loaded from the server, b ...

Issue involving retrieving keys from multiple classes in a JSON object

I am facing some difficulties with JSON and JavaScript as I am a beginner in this area. Currently, I am attempting to iterate through all the keys["name"] of this JSON data. var l = [{ "pages": [ { "name": "Scan", "elements": [ { "type": ...

Avoid clicking on the HTML element based on the variable's current value

Within my component, I have a clickable div that triggers a function called todo when the div is clicked: <div @click="todo()"></div> In addition, there is a global variable in this component named price. I am looking to make the af ...

Utilizing HTTP POST method in vanilla JavaScript with AJAX

Having some trouble sending a post request to my PHP file as it keeps saying 'undefined index'. Here is my JavaScript code: document.getElementById("btn1").addEventListener('click', xh ); function xh(){ xhr = new XMLHttp ...

Understanding how objects are created using the reduce method

I'm curious about how the reduce function can transform an array into an object as shown in this example, particularly with the line: p[c[0]] = c[1]; Is this an unconventional syntax for creating key-value pairs that I haven't encountered before ...

Tips for integrating reCaptcha with AJAX using the .load() function

Looking to integrate reCaptcha with the jQuery '.load' ajax function for passing information to a PHP contact form. Managed to send name, subject, and other values using this method, but unsure about passing reCaptcha info. Encountering a PHP er ...

How to retrieve the current event handler's value with jQuery

To assign an onclick event handler using jQuery, I simply use the following code: $('#id').click(function(){ console.log('click!'); }); Now, my question is how can I retrieve a reference to the function that is currently handling th ...

What is the best way to conceal a set of buttons on the main page using vue.js?

I'm having trouble hiding a button-group on the main page. It should disappear when either the button moveTo(0) is clicked or when scrolling to the top of the page. show: function() { this.scrollTop = (window.pageYOffset !== undefined) ? windo ...

Monitor the DOM for visibility changes in Selenium WebDriver and PjantomJS before proceeding

I am currently creating automated test scripts using selenium-webdriver, phantomJS, and mocha. The script file I'm working with is a JavaScript file. My goal is to wait until an element (<a>) is fully visible before clicking on it. Let me pro ...