EasyUI Forum
May 29, 2024, 06:56:45 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Form submit bug  (Read 9690 times)
zhaowenyi713
Newbie
*
Posts: 4


View Profile Email
« 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");
            }
        });
    }
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 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')
}
}
})
Logged
zhaowenyi713
Newbie
*
Posts: 4


View Profile Email
« Reply #2 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.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!