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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:54:52+00:00 2026-05-16T23:54:52+00:00

doesn’t work.. can’t find any solution to prevent submit page reload only if ajax

  • 0

doesn’t work.. can’t find any solution to prevent submit page reload only if ajax status is 200…

$('form.insarticolo').submit(function (e){  
     function getUrlStatus(url, callback) {
    $.ajax({
        type: "POST",
        url : url,
        data: ({ testo : $('[name=testo]').val() }),
        dataType: "XML",
            success : function(xml) { $('label').find('span').hide();}
        complete: function(xhr) { callback(xhr.status); }
    });
}

getUrlStatus('http://www.website', function(status) {
    if (status == 200)  { 
                    e.preventDefault();
            }
});
}); 
  • 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-16T23:54:53+00:00Added an answer on May 16, 2026 at 11:54 pm

    The .submit() function can be canceled by returning false in the passed function. See http://api.jquery.com/submit/. An issue you may have is that the .ajax() function is asynchronous by default so it will return and processing will continue. To do what you are trying to do you will need to set the ajax mode to synchronous (async : false) so that you can wait for the response. Then you can check the status code to see if it is 200. If it is return false otherwise return true. I haven’t tested this code but something like this

    $('form.insarticolo').submit(function (e){ 
        var retStatus; 
        $.ajax({
            type: "POST",
            url : url,
            async : false,
            data: ({ testo : $('[name=testo]').val() }),
            dataType: "XML",
            complete: function(xhr) { retStatus = xhr.status; });
    
        if(retStaus == 200)
            return false;
        else
            return true;
    });
    

    NOTE: Synchronous requests with jQuery 1.4.2 cause memory issues in IE unless you cleanup the request in the callback function. After processing the xhr you should do the following:

    xhr.onreadystatechange = null; xhr.abort = null; xhr = null;
    

    This is documented at http://dev.jquery.com/ticket/6242

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

Sidebar

Related Questions

C# doesn't require you to specify a generic type parameter if the compiler can
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
It doesn't look like basic javascript but nor can I use JQuery commands like
Doesn't an ORM usually involve doing something like a select *? If I have
Why doesn't this Google Chart API URL render both data sets on this XY
There doesn't seem to be a dictionary.AddRange() method. Does anyone know a better way
There doesn't seem to be an accepted way of sending down a header parameter
ActiveRecord doesn't seem to cater for record locking and database updates. How does one
There doesn't seem to be much info on this topic so I'm going to
WPF doesn't provide the ability to have a window that allows resize but doesn't

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.