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

  • Home
  • SEARCH
  • 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 8461409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:52:21+00:00 2026-06-10T13:52:21+00:00

i am using $.each of jquery like this $.each($(‘.FormContainer div.MainDiv’), function () { $.ajax({

  • 0

i am using $.each of jquery like this

$.each($('.FormContainer div.MainDiv'), function () {
$.ajax({
      type: "POST",
      url: pageUrl + '/SaveFormResponse',
      data: jsonText,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (response) {
      if (isNaN(response.d) == false) {
          //continue executing $.each further
      }
      else {
          alert(response.d);
          //stop executing $.each further in case of error 
      }
      },
      failure: function (response) {
           alert(response.d);
      }

    });

});

now problem is that in case of error i want $.each to stop executing further but it’s not stopping till it will not traverse through all the div’s

i also tried maintaining a variable and check it’s value on every iteration and set it’s value on error but still not working

  • 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-10T13:52:22+00:00Added an answer on June 10, 2026 at 1:52 pm

    When $.ajax gives you a result, $.each has finished already. Note that the first “a” in ajax stands for asynchronous. What you can do is creating a recursive function (you didn’t use anything specific from each element, but I assume you do so I used $elem):

    var $elems = $('.FormContainer div.MainDiv');
    
    (function fetch(i) {
        if(i >= $elems.length) return;  // no elems left
    
        var $elem = $elems.eq(i);
    
        $.ajax({
          type: "POST",
          url: pageUrl + '/SaveFormResponse',
          data: jsonText,
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function (response) {
            if (!isNaN(response.d)) {
              fetch(i + 1);  // next one
            } else {
              alert(response.d);  // just don't call fetch again
            }
          },
          failure: function (response) {
             alert(response.d);
          }
        });
    })(0);  // start with first elem
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$.each(3,function(i){ alert(i) }) alert 0,1,2 how to do this using jquery? thanks
While writing an add to favorites-function using AJAX and certain other jQuery functions like
I've got this problem using jQuery's .each() function. I want to sort the rows
I want to write a function like jQuery each and am using the javascript
I'm having a problem when using the jquery .each() and .ajax() functions together. I'm
I have some code in jQuery that iterate through children in div using each().
I am trying to read a text file using jquery, like this: // LOAD
Suppose I am using the each function on 'myClass' jQuery('.myClass').each(function(){ ...... }); My HTML
I'm using this jQuery plugin which add form fields each time you click the
hi i am using jquery validator plugin , i saw annnotation like this |=

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.