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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:00:36+00:00 2026-05-25T03:00:36+00:00

I have some code below to make sure that a user does not need

  • 0

I have some code below to make sure that a user does not need to click any button and update all input to server side. Server side code is responsible to perform any calculation and send updated JSON back to client.

The issue here is that manual subscription code will detect the user input change, it will call to a function to post JSON data to server and receive JSON from server. From this point it will try to update the view model by calling ko.mapping.updateFromJS(viewModel, data);, but a dead-lock happens here. The updateFromJS will trigger the manual subscription event again, thus server code is called again, which triggers another round of manual subscription.

var initialData = /* get JSON from server side */;

var viewModel = ko.mapping.fromJS(initialData);

ko.applyBindings(viewModel, document.body);

viewModel.Product.Parameter1.subscribe(function(newValue) {
    postToServer();
});

viewModel.Product.Parameter2.subscribe(function(newValue) {
    postToServer();
});

viewModel.Product.Parameter3.subscribe(function(newValue) {
    postToServer();
});

function getProduct() {
    // retrieve JSON data to be posted to server side
}

function postToServer() {
    var product = getProduct();

    $.ajax({
        url: '/Home/ProductUpdate/',
        data: JSON.stringify(product),
        type: "POST",
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            // update JSON returned from server side to observable view-model
            ko.mapping.updateFromJS(viewModel, data);
        }
    });
}

Is it possible to do either of following:

  • Disable manual subscribe while ko.mapping.updateFromJS is called? (Resuming afterwards).
  • Have manual subscription ignore the event triggered by a ko.mapping.updateFromJS call?
  • 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-25T03:00:37+00:00Added an answer on May 25, 2026 at 3:00 am

    Could you do it with a variable like so:

    <script language="javascript" type="text/javascript">
    var initialData = /* get JSON from server side */;
    
    var viewModel = ko.mapping.fromJS(initialData);
    
    var preventUpdate = false;
    
    ko.applyBindings(viewModel, document.body);
    
    viewModel.Product.Parameter1.subscribe(function(newValue) {
        if (!preventUpdate) postToServer();
    });
    

    and then in the postToServer function

    success: function (data) {
        // update JSON returned from server side to observable view-model
    
        preventUpdate = true;
        ko.mapping.updateFromJS(data, viewModel);
        preventUpdate = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code (that is working), but I just want to make sure
I have some code that gives a user id to a utility that then
I have some code that does custom drawing. Basically it is form fill program
I want to make sure my php code and my website does not use
I have some PHP code, listed below. I have a trap that tells me
I have some really funky code. As you can see from the code below
I have some problem with my cfml website. I have used the below code
I have some code in a javascript file that needs to send queries back
I have some code in an IAuthorizationFilter which redirects the user to a login
I have a table generated from some PHP code that lists a SMALL amount

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.