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 6660651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:10:53+00:00 2026-05-26T02:10:53+00:00

My HTML which is at this url ‘/main/’ contains the following link: <a href=/main/

  • 0

My HTML which is at this url ‘/main/’ contains the following link:

<a href="/main/" id="do_something">Do Something</a>

So, the link should do something and then refresh the page.

My jquery looks something like this:

$('#do_something').click(function(event) {

    var my_values = ['1','2'];

    $.ajax({
        url:"/process_values/",
        type: "POST",
        data: {values:my_values},
        success:function(response){
            alert("success: " + response);
        },
        error:function (xhr, textStatus, thrownError){
            alert("xhr status: " + xhr.statusText);
        },

    });

});

The post is executing correctly, but the error callback is always called when it completes.

If I prevent the link from being called using event.preventDefault();, the success function is executed. Why is this? And how do I get the page to update after the post call?

Thanks

  • 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-05-26T02:10:54+00:00Added an answer on May 26, 2026 at 2:10 am

    Without event.preventDefault(), the user is directed to /main/ (because it’s the default behavior of an anchor). Unloading the page causes all pending (XmlHttp) requests to abort, thus triggering the error function (=request has not finished yet).

    An overview:

    • click #do_something
    • fires click event -> Ajax request
    • follows link to /main/.
    • page unloads -> Cancel all requests
    • XHR aborted -> error function triggered

    If you want the page to open, add this at the success function:

    location.href = "/main/";
    

    Alternatively, if you don’t want to hard-code the link:

    $('#do_something').click(function(event) {
        event.preventDefault();
        var linkTo = $(this).attr("href");
        var my_values = ['1','2'];
        $.ajax({
            url:"/process_values/",
            type: "POST",
            data: {values:my_values},
            success:function(response){
                alert("success: " + response);
                location.href = linkTo; //Redirect the user to the new page
            },
            error:function (xhr, textStatus, thrownError){
                alert("xhr status: " + xhr.statusText);
            },
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html page which is very simple, it contains a text box
I've built a jQuery selector for a function which looks like this: $('html').not('.table-main tr[selected]').mousedown(
I have a HTML code which looks like this. <html><head><meta http-equiv=refresh content=0;url=http://www.abc.com/event/></head></html> I want
many doctype use a url link like this <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
I have this HTML code which simulates a dropdown multi-checkbox <div> <div class=select> <span>Select
I have this code which can display drop down in div tag of html.
I have a composite control which emits HTML that looks like this <span id=myControl>
Bearing in mind this is for classic asp Which is better, all HTML contained

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.