We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43888
    • 19 Posts
    hi there,
    i'm trying to use http://vitalets.github.io/x-editable for inline editing. it requires to handle errors using https response code. problem is that modx always replies with a 200. how can i handle it in a snippet?
    thanks in advance
      • 22303 MODX Staff
      • 10,725 Posts
      You'll have to create endpoints to handle your requests to edit data via x-editable. You could do that with a Snippet that calls the appropriate core MODX processor with additional logic to trap errors from the processor and send the appropriate response codes/error messages x-editable requires.
        • 43888
        • 19 Posts
        GOSH! smiley

        maybe your answer is too complex for me (maybe i'm trying to do something beyond my capabilities) or i didn't explain well the issue: i already have a document in modx, from which i just call a snippet that catches the javascript post and persists it on the db. problem is that, if the data passed is in the wrong format/i have an issue with the db, i can't return any error because x-editable recognize my http code 200 as a "everything fine" message... i need to change this code but i don't know how.
          • 22303 MODX Staff
          • 10,725 Posts
          GOLLY GEE! wink

          Now that you have explained some more details, I suppose you might want to do something similar to this in your already existing Snippet:

              header("Content-Type: application/json; charset=UTF-8");
              header('HTTP/1.1 400 Bad Request');
              echo $modx->toJSON(array(
                  'success' => false,
                  'code' => 400,
                  'message' => 'An error occurred...'
              ));
              @session_write_close();
              die();


          Hope that helps a little more...
            • 43888
            • 19 Posts
            thank you very much, it helps a lot.
            as soon as i can try it i'll let you know if it works.
            thanks again