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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:34:04+00:00 2026-05-29T04:34:04+00:00

I have the following javascript and JsonResult. The issue I am having is the

  • 0

I have the following javascript and JsonResult. The issue I am having is the ajax post doesn’t allow enough time for JsonResult to return the appropriate data. I probably don’t completely understand javascript processing and I’m sure this is by design but I’m wondering how I can make this a synchronous request. In short, wait for the JsonResult action to complete before the javascript continues processing.

<script type="text/javascript">
$(document).ready(function () {

    var table = document.getElementById("updateTable");
    var tasks = new Array("shutdown", "prep", "boot", "ready");
    var tasksLength = tasks.length;

    for (var i in tasks) {

        for (var loop = 1, max = table.rows.length; loop < max; loop++) {

            id = table.rows[loop].cells[0].innerHTML;
            task = tasks[i];

            ImageUpdateStatus = {
                ImageId: parseInt(id),
                Task: task,
                Status: "pending"
            }

            $.ajax({
                type: "POST",
                url: "UpdateStatus",
                data: $.postify(ImageUpdateStatus),
                success: function (data) {
                    var status = data.status;
                }
            });

            ImageUpdateStatus.Status = status;

            if (ImageUpdateStatus.Status == "success") {

                task = task.concat(" ");

                document.getElementById(task.concat(id)).src = "/PVSUtil_ver2/Assets/Images/Image.Success.png";

                j = parseInt(i) + 1;
                if (j < tasksLength) {
                    nextTask = tasks[j];
                    nextTask = nextTask.concat(" ");
                    document.getElementById(nextTask.concat(id)).src = "/PVSUtil_ver2/Assets/Images/Image.Load.gif";
                }
            }
        }
    }

    document.getElementById('nextButton').className = "navigation";
    document.getElementById('nextButton').disabled = false;
});

    //
    // GET: /Build/UpdateStatus
    public JsonResult UpdateStatus(ImageUpdateStatus imageUpdateStatus, SessionStateItemCollection sessionItems = null)
    {
        var data = new object();
        string status = null;

        ImageInfo imageInfo = new ImageInfo();
        IImageInfoServices svcImageInfo = new ImageInfoServicesRepository();
        imageInfo = svcImageInfo.GetImageByImageId(imageUpdateStatus.ImageId);

        IDeviceControlServices svcDevice = new DeviceControlServicesRespository();
        IPVSCommandServices svcPVSCmds = new PVSCommandServicesRespository();

        if (imageUpdateStatus.Task == "shutdown")
        {
            status = svcDevice.Shutdown(imageInfo.ImageId);
            //status = "success";

            data = new
            {
                status
            };
        }

        if (imageUpdateStatus.Task == "prep")
        {
            List<UpdateReasonForm> updateReasonForms;

            if (sessionItems.Keys.Count > 0)
            {
                updateReasonForms = sessionItems["UpdateReasonForms"] as List<UpdateReasonForm>;
            }
            else
            {
                updateReasonForms = Session["UpdateReasonForms"] as List<UpdateReasonForm>;
            }

            foreach (var item in updateReasonForms)
            {
                if (item.ImageId == imageInfo.ImageId)
                {
                    status = svcPVSCmds.PrepImage(imageInfo, item.NewVersion);
                }
            }

            data = new
            {
                status
            };
        }

        if (imageUpdateStatus.Task == "boot")
        {
            status = svcDevice.Boot(imageInfo.ImageId);

            data = new
            {
                status
            };
        }

        if (imageUpdateStatus.Task == "ready")
        {
            status = "success";

            data = new
            {
                status
            };
        }

        return this.Json(data, JsonRequestBehavior.AllowGet);
    }
  • 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-29T04:34:05+00:00Added an answer on May 29, 2026 at 4:34 am

    Just move the code that relies on the result from the ajax request into the success callback function:

    $.ajax({
        type: "POST",
        url: "UpdateStatus",
        data: $.postify(ImageUpdateStatus),
        success: function (data) {      
            ImageUpdateStatus.Status = data.status;
    
            if (ImageUpdateStatus.Status == "success") {
    
                task = task.concat(" ");
    
                document.getElementById(task.concat(id)).src = "/PVSUtil_ver2/Assets/Images/Image.Success.png";
    
                j = parseInt(i) + 1;
                if (j < tasksLength) {
                    nextTask = tasks[j];
                    nextTask = nextTask.concat(" ");
                    document.getElementById(nextTask.concat(id)).src = "/PVSUtil_ver2/Assets/Images/Image.Load.gif";
                }
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
In javascript I have the following: $.ajax({ url: /ajax/test, type: POST, dataType: html, data:
i have the following javascript to post a form through ajax without refreshing the
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following javascript: $.post(/Authenticated/DeletePage/ + PageId); showStatus(Page deleted..., 10000); I would like
I have the following javascript function for rounding: function round(val, numberdigits){ return Math.round(val*Math.pow(10, numberdigits))/Math.pow(10,
I have the following javascript snippet: $.ajax({ url: self.LoadCirculationListUrl, cache: false, async: false, dataType:
I have the following JavaScript: var djs = function (ob) { return { remove:
I have the following javascript functions: function fun1() { ... return 'Over'; } function
i have the following javascript below after i finish an ajax query all of

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.