Handling PHP exceptions with JQuery

前端 未结 4 1194
野性不改
野性不改 2021-01-15 10:08

I\'m using JQuery to call a PHP function that returns a JSON string upon success or throws some exceptions. Currently I\'m calling jQuery.parseJSON() on the res

4条回答
  •  一个人的身影
    2021-01-15 11:02

    Catch the exception on the PHP end, and output an error message in JSON format:

    echo json_encode(array(
        'error' => $e->getMessage(),
    ));
    

提交回复
热议问题