Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:40:57+00:00 2026-06-04T18:40:57+00:00

I need jQuery to post to a relative url (currently its posting to the

  • 0

I need jQuery to post to a relative url (currently its posting to the root).

Structure:

  1. site url: localhost/myApp
  2. Form url: Account/Login
  3. actual server url: localhost/myApp/Account/Login <- need it here
  4. posting to url: localhost/Account/Login

Form:

<form id="login" action="Account/Login" method="POST">
</form>

jQuery:

$.post($el.find('form').attr("action"), $el.find('form').serialize(), function(resp) {
});

I need to be able to put this app in any URL and it works, so if its hosted at www.site.com/dir1/dir2/, then it should post to www.site.com/dir1/dir2/Account/Login.

Note, this is a single page app. So the form is located at localhost/myApp.

Headers Info:

Request URL:http://localhost/Account/Login
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:19
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost
Origin:http://localhost
Referer:http://localhost/myApp
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
X-Requested-With:XMLHttpRequest
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:40:59+00:00Added an answer on June 4, 2026 at 6:40 pm
    Request URL:http://localhost/Account/Login
    Request Method:POST
    Status Code:404 Not Found
    Request Headersview source 
    ...
    ...
    Referer:http://localhost/myApp
    

    Although you’re loading /myApp, it’s clear that some form of redirection is taking place that is dropping the client at the root / path:

    Thus, in your action, add the following to the action attribute:

    <form action="/myApp/Account/Login">
    

    As an aside, you either have a 301/302 redirect that is rewriting the URL to http://localhost, or you’re not really visiting http://localhost/myApp, or you could possibly have a <base> HTML element that is causing your relative URLs to get thrown off. Without seeing all of the HTML, it’s difficult to say for sure, but changing the path in the action will connect your form to the server.

    If the root of your application changes from platform to platform, consider using the <base> HTML element to avoid needing to change all of your URLS. With <base>, you simply make the change in 1 place in the HTML.

    <!-- relative urls start from /myApp -->
    <base target="_blank" href="http://localhost/myApp/">
    

    For more information, please see the Mozilla Developer Center article on the base HTML element:

    href

    • The base URL to be used throughout the document for relative URL addresses.
    • If this attribute is specified, this element must come before any other elements with attributes whose values are URLs.
    • Absolute and relative URIs are allowed (but see note section below).

    Also, while information from W3Schools should be digested with some scrutiny, I list the page on the base HTML element here, simply because they have a better example than MDC:

    <head>
        <base href="http://www.w3schools.com/images/" target="_blank" />
    </head>
    
    <body>
        <img src="stickman.gif" />
        <a href="http://www.w3schools.com">W3Schools</a>
    </body>
    

    Here is the obligatory W3Fools link.

    NOTE: The base element must come before any other element that refers to the URLs that are modified by the base element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing an Edit Account module. Using jQuery.post(); I can successfully update
edited: This is what i need: sendpost = function(a,b,c){ return jQuery.post('inc/operations.php', {a:b}, c, json);
I have an HTML form that I need to post to the server with
I'm using this jQuery Validation script to submit my form(s), but I need some
Quite often i need to add/delete/update the item in database via Jquery POST. Now
I am doing a simple jQuery post: $.post('/form.html', $(#form).serialize(), function(data, textStatus) { //Selector for
I am posting a jQuery AJAX POST to a servlet and the data is
How do I post a form using jQuery.post() to a Coldfusion.cfc method and return
In the sample I've put together, I need to: Use a jquery POST inside
I need a jquery slideshow with div popup i want to show my image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.