0

Submitting a page form results in an ajax call to a backend service which returns an json object. The object is than bound to a vue.js template (a div with a particular id). Everythiong works as expected on the first submit. However, the view is not updated on any following form submits (it still shows the data from the first submit).

<div id="Response"></div>

$('#Form').submit(function (e) {
    e.preventDefault();
    var $form = $(e.target);
    $.ajax({
        url: 'https://somewhere,
        type: 'POST',
        data: $form.serialize(),
        dataType: 'json',
        success: function(response) {
            if (response) {
                var app = new Vue({
                    el: '#Response',
                    data: response
                });
            }
        }
    });
});

How to do this properly so each time the form is submitted, the view is updated appropriately based on the last response?

1 Answer 1

1

Now you are creating a new vue instance with each response. You need to mount the vue instance first, then use the response to update the data in it.

Sign up to request clarification or add additional context in comments.

1 Comment

It's just not that straightforward as I could not update the data property directly (as one should not replace the root data object) but I need to create a new property in it and use that to store the response object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.