Error_page now outputs json if the request is json

Makes troubleshooting errors from rest interface slightly
more convenient
raymii - minor javascript fixes