Sending a URL through the $.post method to various websites

Trying to populate my address using JavaScript

  $.post('/Endereco/getEnderecos', { CardCode: dado }, function (data) {
    if (data) {
  (...)

Encountering an issue: when I host my website on 'localhost', it works fine, but when hosted on "localhost/site" or "www.mydomain.com/site", the functionality breaks.

My website is built in C# asp.net MVC3 with IIS7

I attempted to retrieve the host using JavaScript, but without success

Any insights would be appreciated. Thank you

Answer №1

Your website address contains a leading slash in /Endereco/getEnderecos, which can lead the browser to navigate to the root of the current host followed by the provided URL.

For instance, if you post to /somePage from a page located at

www.mysite.com/folder/subfolder/page
, it will actually post to www.mysite.com/somePage.

To fix this issue, remove the slash before Endereco, so your post should be like this:

$.post('Endereco/getEnderecos', { CardCode: dado }, function (data) {
  if (data) {
(...)

In response to your query, you could use the .. notation to go up a folder:

$.post('../../Endereco/getEnderecos', { CardCode: dado }, function (data) {
  if (data) {
(...)

If your original URL is

localhost/order/Endereco/getEnderecos
, after using two .. components, the resulting URL would be localhost/Endereco/getEnderecos, as it went up two folders instead of one.

I came across a helpful tutorial on relative URLs that might give you more insight into HTTP URLs: . It could assist you in understanding HTTP URLs better =]

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

Designing this unique shape using CSS3 to create a sleek drop-down container

My goal is to design something that resembles the following: The challenge lies in my preference to contain it within a single div, considering the drop-down features an inner shadow and a drop shadow. Thank you in advance, and please feel free to ask fo ...

Activate a module within a Vuex action only upon dispatching

Is there a way to import a package for use in a Vuex Action only when the Action is dispatched, in order to reduce the size of my entry bundle? Here's what I've tried: export const actions = { async createNewBin(store, bin) { const fireba ...

Failure of ConfirmButtonExtender to function properly when dynamically added to control collection

I've been attempting to dynamically add a ConfirmButtonExtender to my controls collection within a custom control during runtime. However, I can't seem to get the extender to wire to the button being added to the controls collection in the Create ...

Switch: Determine if a character or string falls within a specific range without using regular expressions

Looking for alternative ways to determine if a character is a letter or number without relying on RegEx. Here's the current code I have: void IdentifyChar(char Chr) { switch (Chr) { case // A..Z or A-Z } } I am certain there is a ...

The appearance of the check box remains stagnant visually

Having trouble with dynamically changing the state of a checkbox based on a database value. Even though the value changes after a button click, the visual state of the checkbox remains the same. Here is the link to the JSFiddle for testing: http://jsfiddle ...

Leveraging the Selenium IE driver with C# to efficiently publish a substantial volume of text consisting of 10,000 lines

Currently, I am working on a script to automate a repetitive task using the Selenium Internet Explorer driver in C#. Everything is running smoothly, but there is a slight delay during one particular part of the script. I am exploring if there is a faster w ...

Having trouble getting CSS3 Keyframes to function properly?

Check out the following code snippet: .startanimation { height: 100px; width: 100px; background: yellow; -webkit-animation: animate 1s infinite; } @-webkit-keyframes animate { 100% { width: 300px; height: 300px; } ...

Next.js Error: The text displayed on the page differs from the HTML rendered by the server

Currently, I am facing an issue with the error "Error: Text content does not match server-rendered HTML." Here is my scenario - I have received a dateTime from an API, for example '2022-12-25T11:22:37.000Z', and I want to display it on a compone ...

Please select the option to choose all values

Currently, I am working on implementing a select option feature on my webpage. I have integrated PHP into it to ensure that the selected option remains unchanged after submission. My goal is to include a value of "any" so that when the user chooses "ANY," ...

Ways to avoid automatic error correction when running npm lint?

Utilizing the Vue CLI, I developed a Vue3 app with a Prettier/Eslint configuration. Upon making changes to the main.ts file as shown below: import { createApp } from "vue"; import App from "./App.vue"; import router from "./router& ...

Stopping autoplay in Swiper as soon as you hover over it

My swiper is set to autoplay, but I want it to stop immediately when hovered over instead of waiting for the transition to finish. Is there a way to interrupt the transition and stop it at the exact point where the cursor hovers? Here is my Swiper config ...

What is the best way to combine a QR code and an existing image using Java script?

Looking for help in embedding a created QR code into an existing image. I am proficient in nodeJS, JavaScript, and jQuery. Any assistance would be greatly appreciated. ...

Experiencing difficulties posting on route due to receiving an undefined object instead of the expected callback in Node Js

I am working on implementing a feature in my application where users can create a favorite route. When a user adds a campground to their favorites, the ID of the campground is saved in an array within the schema. The process involves checking if the campgr ...

The error message "Trying to call zmq.zmqVersion as a function, but it's not a function" occured while attempting to import the ZeroMQ

My current project involves creating a react app that can subscribe to an IPC socket using JavaScript code. I chose to use npx create-react-app for this purpose. To handle the subscription, I decided to utilize the npm package zeromq. However, when instal ...

The input '{ data: InvitedUser[]; "": any; }' does not match the expected type 'Element'

I'm currently facing a typescript dilemma that requires some assistance. In my project, I have a parent component that passes an array of results to a child component for mapping and displaying the information. Parent Component: import { Table } fr ...

Boundaries on Maps: A guide to verifying addresses within a boundary

User provides address on the website. If the address falls within the defined boundary, it is marked as "Eligible". If outside the boundary, labeled as "Ineligible". Are there any existing widgets or code snippets available to achieve this functio ...

Update a separate React component in response to the interaction with a different React component

Currently, I am working with a react component named Interest Category that showcases an initial set of Interest categories. Another react component called CreateInterestCategoryDialog, which functions as a modal, is responsible for creating a new entity I ...

Creating JSON arrays with JavaScript and jQuery

User Information var Users=[{"Id":1,"FirstName":"John"},{"Id":2,"FirstName":"Emily"}] Call Information var CallInfo=[{"Id":1,"PercentageCalls":"22 %","TotalTime":"60:24 minutes","PercentageTime":"0 %","AvgTime":"0:22 minutes"},{"Id":2,"PercentageCa ...

What is the best way to ensure that JavaScript is loaded in a specific sequential order?

I'm having trouble ensuring that JS files load in the correct sequence, despite my efforts to research async and defer on various platforms. This is the structure of my code: <script src="lang.js"></script> <!--loading either ...

Issue encountered while appending new rows to the tbody of a table

I'm encountering an issue with the append function within a for loop in my code. The string being passed to the function isn't parsing correctly and results in an error. How can I go about resolving this problem? Thanks! function getDetailPopUp ...