提交表单后阻止更改吗? [英] Prevent changes after async form submission?

查看:76
本文介绍了提交表单后阻止更改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个称为SubmitEdit()的函数:

So I have a function called submitEdit():

function submitEdit() {
    //var ffield = document.getElementById("form_eline");
    //ffield.submit();
    jQuery('#edit_line').css('visibility', 'hidden');

    var fieldName = jQuery('#form_eline input[name=efield]').val();
    var pageId = jQuery('#form_eline input[name=eid]').val();
    var fieldText = jQuery('#ve'+fieldName+'_'+pageId);
    var editBtn = fieldText.prev();
    var loading = document.createElement("img");
    loading.src = 'http://www.lookall.tv/html/res/img/loading.gif';
    loading.id = "loading";
    loading.width = 16;
    loading.height = 16;

    jQuery('#form_eline').ajaxSubmit({
        beforeSubmit: function() {
            editBtn.hide();
            fieldText.prepend(loading);
        },
        error: function(data) {
            jQuery('#edit_line').css('visibility', 'visible');
        },
        success: function(response) {
            fieldText.text(jQuery('#form_eline :text').fieldValue()[0]);
            editBtn.show();
            jQuery('img#loading').remove();

            return true;
        }
    });
}

可悲的是,这不是我的工作,我正在建立一个已经存在的网站.因此,问题在于服务器的响应速度很慢.因此,在那几秒钟内,服务器需要发送响应,有人可以编辑另一个字段,从而覆盖当前值.有什么方法可以实例化变量,以使它们不会被覆盖?

Sadly this isn't my work and I'm building on an already existing website. So the problem is that the server is slow to respond. Therefor in those few seconds it takes the server to send a response someone could edit another field thus overwriting the current values. Is there some way to instantiate the variables so they don't overwrite?

推荐答案

如果用户更改HTML元素的值,variables不会受到影响.

The variables won't be affected if the user will change the values of the HTML elements.

如果您希望用户知道他所做的更改,则不会受到影响,因为请求已被发送.只需禁用元素即可.

If you want the user to know the changes he will do won't affect because the request ha been sent already. just disable the elements.

beforeSubmit: function() {
            editBtn.hide();
            fieldText.prepend(loading);
            $('#form_eline input, select, textarea').prop('disabled', true);
        },
complete: function (){
            editBtn.show();
            $('#form_eline input, select, textarea').prop('disabled', false);
        }

这篇关于提交表单后阻止更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆