• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[SOLVED] 500 (Internal Server Error) On Ext.Ajax.request (No Success Fired)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED] 500 (Internal Server Error) On Ext.Ajax.request (No Success Fired)

    This exact same code works in another app (outside of the app I'm working on). It's coded as a non-MVC app.

    The "making saveRecord ajax call" shows up in the log.
    The "ajax request success" does not show up in the log.
    The Ajax Failure message window shows up.

    Here is the error in Chrome Tools:

    Code:
    POST http://mysystem:6031/valence/vvcall.pgm 500 (Internal Server Error) ext-all.js:15
    Ext.define.request ext-all.js:15
    saveRecord vvcall.pgm:400
    Ext.create.dockedItems.items.handler vvcall.pgm:655
    Ext.define.fireHandler ext-all.js:15
    Ext.define.onClick ext-all.js:15
    (anonymous function)
    c
    line 655 is the save button in a window making the function call to saveRecord(outMode).
    line 400 is the ajax request singlton.


    Here is my saveRecord function that makes the ajax call. This is executed from a save button in a window.

    Code:
        function saveRecord(inMode) {
    
            continueValidation = true;
        
            // continue validation if field depencies validated
            if (continueValidation) {
                
                console.log('making saveRecord ajax call');
                
                Ext.Ajax.request({
                    url: 'vvcall.pgm',
    	        	params: {
    		    		pgm: 'MYPGM',
        	    		action: 'saveRecord',
                        inMode: inMode
    		     },
        	    	success: function(response) {
                        console.log('ajax request success');
        		    	var data = Ext.decode(response.responseText);
            	    	if (data.SUCCESS == '1') {
                            Valence.util.msg({
                                title: 'Saved',
                                msg: data.MSG,
                                el: myGrid.el,
                                slideFrom: 'r'
                            });
                            // hide form window and reload grid
                            myWindow.hide();
                            jmyDataStore.loadPage(1);
    		        	   } else {
                            console.log('the bad field = '+data.FLD);
                		   	try {
                                if (data.FLD !== ' ') {
                                    jprrsnFormPanel.down('#' + data.FLD).markInvalid(data.MSG);
                                }
                            } catch(e){																					
    		    	    	    Ext.Msg.alert('Ajax Response Unmonitored','An unmonitored error occured when attempting to save record');			
        		        	}
                        }
    		   	    },
    		        failure: function() {
                        Ext.Msg.alert('Ajax Failure', 'Received a failure response from the server when attempting to save record.');
    	    	    }
                });
            }
        }
    Last edited by rkanemeier; 03-12-2015, 02:21 PM.

  • #2
    I also tried making the function an actual object and that does not work:

    var saveRecord = function(inmode) {
    };

    Comment


    • #3
      It might have been prudent to make sure my RPG program compiled after added the following code:

      Code:
      vvOut_toJSONpair('SUCCESS:1,'+                       
                       'MSG: Record successfully updated');
      My program never returned a response. On top of that, I should have tried parsing out the var data = Ext.decode(response.responseText); That would have given me some clue that the call was at least executing. /sigh

      Comment


      • #4
        Good lesson! Typically when you see that kind of "500 Internal Server Error" on the response in your console it's because the RPG program ended without vvOut'ing something to the front end. This, of course, triggers the "failure" function in your Ajax call if you have it defined. The failure function would also be executed if the RPG program goes into a MSGW state or hits a loop that exceeds the timeout of the Ajax call (which is 30 seconds by default -- you can override that by adding a timeout: config).

        Although in your case the problem was caused by a SUCCESS:1 not being sent back until you recompiled your RPG program with the added code, often times we see this happen because the "action" being passed to the back-end has a typo or wasn't expected by the RPG program being called. For that reason it's a good idea to always include a fallback in the section of your RPG code that checks the action, ensuring the program can't terminate without sending some kind of response. i.e., something like this:
        Code:
        if action = 'getRecord';
          getRecord();
        elseif action = 'deleteRecord';
          deleteRecord();
        elseif action = 'saveRecord';
          saveRecord();
        else;
          vvOut_toJSONpair('SUCCESS:0,MSG:Action '+%trim(action)+' not expected');
        endif;
        On the front-end it's also a good idea to get in a habit of including an "else" clause against your check for SUCCESS==='1' to handle back-end errors.

        Comment


        • #5
          Robert, thanks for your informative reply. I actually do check for success. When there is a failure, I simply throw up a window stating there was an AJAX failure. Can you provide any insight on how to use the response.data to get a more "informative" error message?

          Comment


          • #6
            I assume you've got the (SUCCESS==='0') case handled -- you'd just throw up a message box with whatever error text (MSG) the RPG program returned to your app.

            For the "failure" clause of the Ajax call, there's not much you can tell the user about what exactly went wrong since nothing meaningful will have been returned from the IBM i (there's no "response.data" to work with). But the user could still help IT zero in on the problem with information on which program was called and what action was passed.

            So I'd suggest having your Ajax call's failure function throw a pop-up message with that info. You could even set up a generic function in your controller code to handle this, adding the function to the failure config of every Ajax call that includes "pgm" and "action" parms.

            For example...
            Code:
            // Ajax call to RPG program...
            
            getOrderHeaderData: function(order_number) {
            
                 Ext.Ajax.request({
            
                        url: 'vvcall.pgm',
            
                        params: {
                            pgm: 'RPG_ORDHDR',
                            action: 'getHeaderData',
                            ordno: order_number
                        },
            
                        scope: this, // (so the failure config below can "see" the notifyAjaxFailure function)
            
                        success: function(response) {
            
                            var d=Ext.decode(response.responseText);
                            if (d.SUCCESS==='0'){
                                // RPG program encountered a trapped error
                                Ext.Msg.alert('ERROR ENCOUNTERED',d.MSG);
            
                            } else {
                                // RPG program did its thing successfully...  carry on.
                            }
                        },
            
                        failure: function(response, opts) {
            
                            // no response from the RPG program!
                            this.notifyAjaxFailure(response, opts)
                        }
                    })
            },
            
            
            // generic routine to handle Ajax failures... 
            
            notifyAjaxFailure: function(response, opts) {
            
                 Ext.Msg.alert('ERROR ENCOUNTERED','Failed to receive response from program ' + opts.params.pgm +
                                       ' on action ' + opts.params.action + '.  Please notify IT');
            }

            Comment

            Working...
            X