We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15114
    • 102 Posts
    Hi,

    I try to execute an action with an ajax request (from a grid).
    All seems to works correctly, the data I want are loaded. But it's allways the 'failure' function that is called

    Here is my function :

    ,sendMail: function() {
                  
                  
                  MODx.Ajax.request({
                         url : Taichitcho.config.connectorUrl,
                params: {
                  action: 'mgr/adresse/getList'
                },
               
                listeners: {
                   'success': {
                         fn: function(r) {
                               alert(r); //test
                         }
                  },
                  
                   'failure':{
                         fn: function(r) {
                               alert(r); //test
                         }
                    }
                }
            });
        }




    Config :
    OS : Windows 8.1 64 bits
    Apache: 2.2.22
    PHP: 5.3.13
    MySql : 5.5.24
    MODX : 2.2.13-pl


    Regards

    Julien

    This question has been answered by JuTs. See the first response.

      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Mark Hamstra Reply #2, 12 years ago
      What's the return value from the AJAX request?

      And given that your success and failure handlers are both the same, how do you know which one is triggering? laugh
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 15114
        • 102 Posts
        Quote from: markh at Oct 16, 2014, 07:25 AM
        What's the return value from the AJAX request?

        It returns the data found by my getList action.

        Quote from: markh at Oct 16, 2014, 07:25 AM
        And given that your success and failure handlers are both the same, how do you know which one is triggering? laugh

        Using the browser (Firefox) debugger.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Mark Hamstra Reply #4, 12 years ago
          Could you paste an example JSON return value? Also what is the HTTP response code on the request?
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • discuss.answer
            • 15114
            • 102 Posts
            I found the solution here : http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/custom-manager-pages/modext/modx.console

            Modx.Ajax.request expects a 'success' key value return in json, so you have to return 'success' in the processor. Otherwise the success listener will never fire.

            In my case, the success key was missing. So I added

            public function outputArray(array $array,$count = false) {
            	if ($count === false) { 
            		$count = count($array); 
            	}
            		
            	return '{"success":"1","total":"'.$count.'","results":'.$this->modx->toJSON($array).'}';
            }


            in my GetListProcessor

            Julien