Results 1 to 6 of 6

Thread: Handle server errors like Fatal error, Warning, Notice on Ajax.request, form.submit

  1. #1
    Sencha User eliotik's Avatar
    Join Date
    May 2010
    Posts
    27

    Question Handle server errors like Fatal error, Warning, Notice on Ajax.request, form.submit

    Hello. How can i catch server errors like Fatal error, Warning, Notice in php script while i do ext.ajax.request or form.submit?
    listener actionfailed for form submit dont work
    and
    listener for ajax.request requestexception dont work
    i know, you can say that js can not know about php script error, but for example jQuery when you use $.ajax() on ajax.event "error" can handle parse error, yes all php script error like Fatal errors, Warnings, Notices and other can be handled by ajax.event "error" (parsererror).
    may be i dont know how do same thing in ext or may be its not possible with ext?
    thank you for help.

  2. #2
    Sencha User eliotik's Avatar
    Join Date
    May 2010
    Posts
    27

    Default

    i mean, how can i fix this when do ajax.request or form.submit:
    :::response:::
    missing ) in parenthetical
    [Break on this error] <b>Fatal error</b>: Call to undefined...ient.php</b> on line <b>217</b><br />\n
    ext-all-debug.js (?????? 4234)
    PHP Code:
     doDecode = function(json){
       return eval(
    "(" json ")");
     }, 
    ofcourse i can do try/catch in the php script and return json response, and its may be will be right decision, but i want for sure to have ability to handle this type of errors on ajax.request and form.submit like in jquery .

  3. #3
    Sencha User eliotik's Avatar
    Join Date
    May 2010
    Posts
    27

    Default

    for ajax.request i did next:
    PHP Code:
    var ajax = new Ext.data.Connection({
      
    listeners: {
        
    'requestcomplete': {
          
    fn: function(conresopt){
            try {
              
    Ext.util.JSON.decode(response.responseText);
            } catch (
    e) {
              
    Ext.Msg.show({
                
    closablefalse,
                
    title'Error',
                
    iconExt.Msg.ERROR,
                
    msg'Bad response from server: '+response.responseText,
                
    buttonsExt.Msg.OK
              
    });
            }
          },
          
    scopethis
        
    }
      }
    });

    ajax.request({...}) 
    and it works

    but trouble left with form.submit . event 'actioncomplete' dont work.

  4. #4

    Question

    Any body know how to handle this ? can't seem to work it

    i think its because in the XHR request it self is success ( http status 200, but the response it self is not in JSON format as expected )

    The handler of the submit actin is in the Ext.form.Action.Submit class is executing these method : success -> processResponse -> handleResponse. the problem seems to come from this code : return Ext.decode(response.responseText) in the handleResponse method. this execution seems to fail, and the process just stopped, dont return error or continue the process.

  5. #5

    Default

    i think i've found a way, but has'nt tested it in other browser

    PHP Code:
    Ext.override(Ext.form.Action.Submit, {
        
    handleResponse : function(response){
            if(
    this.form.errorReader){
                var 
    rs this.form.errorReader.read(response);
                var 
    errors = [];
                if(
    rs.records){
                    for(var 
    0len rs.records.lengthleni++) {
                        var 
    rs.records[i];
                        
    errors[i] = r.data;
                    }
                }
                if(
    errors.length 1){
                    
    errors null;
                }
                return {
                    
    success rs.success,
                    
    errors errors
                
    };
            }
            
            
    // return Ext.decode(response.responseText); // original code
            
    try {
                var 
    xTmp Ext.decode(response.responseText);
                return 
    xTmp;
            } catch(
    exp) {
                return 
    false;
            }
            }
    }); 

  6. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    216

    Default exception

    PHP Code:
    Ext.Ajax.request({
        
    url' ',

        
    method'GET',
        
    success: function (responseoptions) {
            
    Ext.decode(response.responseText);
            if (
    x.success == 'true') {
                
    Ext.MessageBox.alert('SYSTEM'x.message);
                
    box.hide();
            } else {
                
    Ext.MessageBox.alert('SYSTEM'x.message);
            }

        },
        
    failure: function (responseoptions) {
            
    status_code response.status;
            
    status_message response.statusText;
            
    Ext.MessageBox.alert('system'escape(status_code) + ":" status_message);
        }
    }); 
    PHP Code:
    formPanel.getForm().submit({
        
    waitMsgwaitMessageLabel,
        
    params: {
            
    method'save',
            
    leafIdleafId
        
    },
        
    success: function (
        
    formaction) {
            var 
    title successLabel;
            
    Ext.MessageBox.alert(
            
    titleaction.result.message);
            
    formPanel.getForm().reset();


        },
        
    failure: function (formaction) {

            if (
    action.failureType === Ext.form.Action.LOAD_FAILURE) {
                
    alert(loadFailureMessageLabel);
            } else if (
    action.failureType === Ext.form.Action.CLIENT_INVALID) {
                
    // here will be error if duplicate code
                
    alert(clientInvalidMessageLabel);
            } else if (
    action.failureType === Ext.form.Action.CONNECT_FAILURE) {
                
    Ext.Msg.alert(form.response.status ' ' form.response.statusText);
            } else if (
    action.failureType === Ext.form.Action.SERVER_INVALID) {
                
    Ext.Msg.alert(failureLabelaction.result.message);
            }
        }

    }); 
    hope help
    Last edited by alien3d; 6 Feb 2011 at 7:52 AM. Reason: CHANGE CODE TAG TO PHP TAG

Similar Threads

  1. Error on wiki: Difference between Ajax.request and Form.submit
    By DocSavage in forum Community Discussion
    Replies: 4
    Last Post: 16 Aug 2013, 10:32 PM
  2. Extjs and PHP fatal errors
    By gr_great_2000 in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 15 Sep 2010, 2:15 AM
  3. Hello, I'm having errors in Submit Form... Ajax communication failed
    By birkoff rsx in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 25 Aug 2010, 1:23 AM
  4. How can i intercept the form's submit in the ajax request?
    By brumby007 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 19 Feb 2008, 12:16 AM
  5. Can`t submit a form with ajax.request
    By dolittle in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 8 Oct 2007, 3:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •