EasyUI Forum

General Category => Bug Report => Topic started by: zhaowenyi713 on November 11, 2014, 06:01:05 PM



Title: Form submit bug
Post by: zhaowenyi713 on November 11, 2014, 06:01:05 PM
I find that submit method can't accept error event.When the program produce a bug (server 500), the success event will happen.
I know EasyUI always validate mistake in validatebox, but some validate have to do in submit method(in back ground code,such as C# ,Java). When it's happen, I should catch and treat them.
But now, because of  current situation, I have to use $.ajax to submit my data in trouble. I have to collect data by explicit code.

so,for example,I have to submit my form data such as this type.

function save() {

        var nameCN = $('#txt_NameCN').textbox('getValue');
        var nameEN = $('#txt_NameEN').textbox('getValue');
        var indexCode = $('#txt_IndexCode').textbox('getValue');
        var remarks = $('#txt_Remarks').textbox('getValue');

        var data = {
            NameCN: nameCN,
            NameEN: nameEN,
            IndexCode: indexCode,
            Remarks: remarks
        }
        $.ajax({
            type: "POST",
            url: "/Kit/Save",
            data: data,
            dataType: "json",
            error: function (ajaxExceptionModel) {
                var obj = jQuery.parseJSON(ajaxExceptionModel.responseText);
                $.messager.alert('Error Info', obj.ErrorMessage, 'error');
            },
            success: function (operationResult) {
                showMessage("Save Successful");
            }
        });
    }


Title: Re: Form submit bug
Post by: jarry on November 11, 2014, 07:00:51 PM
When using the 'form' plugin to submit a form, you need to detect if the returned data is valid.
Code:
$('#ff').form('submit', {
success: function(data){
try{
var data = eval('('+data+')');
if (data.success){
console.log('ok')
}
} catch(e) {
console.log('err')
}
}
})


Title: Re: Form submit bug
Post by: zhaowenyi713 on November 11, 2014, 07:44:28 PM
When using the 'form' plugin to submit a form, you need to detect if the returned data is valid.
Code:
$('#ff').form('submit', {
success: function(data){
try{
var data = eval('('+data+')');
if (data.success){
console.log('ok')
}
} catch(e) {
console.log('err')
}
}
})
Thank you,but don't you think it is strange? and all of my response data have to have a fixed structure. And my process depends on the Property-'success' completely.I hope that the 'form' could have a error event.


Title: Re: Form submit bug
Post by: jarry on November 12, 2014, 01:25:43 AM
The returning 'success' property is not necessary. You can return your own data structure. Normally you should distinguish the processing result in your background server. If some errors occur, you need to return it to the browser to tell the user what errors happen.