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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:59:15+00:00 2026-05-31T15:59:15+00:00

I have the following jQuery: var fn = { Load: function () { $(.myclass

  • 0

I have the following jQuery:

var fn = {
    Load: function () {
        $(".myclass input.Submit").click(function (e) {
            var _IsValid = fn.IsValid();
            if (_IsValid == false) {
                e.preventDefault();
            }
            //Popup displays message fine if "return false;" is
            //called here but then obviously never posts back.
        });
    }
, IsValid: function () {

    var _IsValid = true;
$.ajax({
       url: "/myURL"
       , type: 'POST'
       , contentType: 'application/json; charset=utf-8'
        , data: JSON.stringify({ Barcode: $barcode.val(), Email: $email.val() })
        , dataType: 'json'
       , success: function (data) {
          var array = eval(data);
          if (array[0] == 0) {
            _IsValid = false;
            ShowPopup(array[1]);
          }
         }
       , error: function (xhr, status, error) {

         }
    });
   return _IsValid;
 }
}

AJAX response is 200 OK, but the success function is not being ran. Instead it seems to be running the error function.

The script is being ran as an click event listener for an ASP.NET ImageButton. If _IsValid==false, then e.preventDefault() is invoked to prevent postback.

What’s strange is that if I add return false to the end of my event listener function, this code runs the success function.

How can I find out what is causing this to error so that I can resolve it?

  • 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-31T15:59:16+00:00Added an answer on May 31, 2026 at 3:59 pm

    I think the problem you currently have is that your IsValid function will always return true. This is because the AJAX post will not have time to complete before the function is returned. It is an asynchronous function after all.

    From what I can tell you want to valid a form with an AJAX request and if valid submit the form, otherwise show a popup. If that is correct you should do something like…

    $(".myclass input.Submit").click(function (e) {
        e.preventDefault();
        ProcessForm();
    });
    
    function ProcessForm(){
       $.ajax({
           url: "/myURL"
           , type: 'POST'
           , contentType: 'application/json; charset=utf-8'
            , data: JSON.stringify({ Barcode: $barcode.val(), Email: $email.val() })
            , dataType: 'json'
           , success: function (data) {
              var array = eval(data);
              if (array[0] == 0) {
                ShowPopup(array[1]);
              }
              else//VALID
              {
                 document.forms[0].submit();
                 //OR IF YOU HAVE MULTIPLE FORMS SPECIFY AN ID...
                 document.getElementById("FormElement").submit();
              }
             }
           , error: function (xhr, status, error) {
    
             }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following jQuery code $('a.editpo, a.resetpass').click(function(event){ event.preventDefault(); var urlToCall = $(this).attr('href'); var hyperlinkid
I have the following jquery code: $(.rotateNews).load(/load_news.php); var refreshId = setInterval(function() { $(.rotateNews).load('/load_news.php?newsID='); },
I have the following jQuery script... $(function() { $('.eventWrapper').bind('click', function(event) { var srvName =
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following home-grown jquery plugin: (function($) { $.fn.defaultButton = function(button) { var
I have this code in jquery: var ratio; $(<img/>).attr(src, $(img).attr(src)).load(function() { ratio = this.width
I have the following jquery code $(document).ready(function() { //Default Action $(#playerList).verticaltabs({speed: 500,slideShow: false,activeIndex: <?=$tab;?>});
I have the following code: $(function () { var html = $('<div></div>'); html.load('preview.html', function
I have following jquery: $(window).resize(function () { changeIframe(); }); $(#iFrame).load(function () { changeIframe(); });
i have following variables in jquery var uemail=abc@domain.com,xyz@domain.com,gty@domain.com; var subj=test message; var text=<b>This is

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.