-
Notifications
You must be signed in to change notification settings - Fork 4
OUT_MSG_DESCRIPTION
Jurek Muszyński edited this page Mar 28, 2024
·
12 revisions
Writes error code, category and description to output buffer.
By default, it uses JSON format:
{"code":4,"category":"err","message":"Page not found"}If NPP_MSG_DESCRIPTION_PIPES is defined, it uses pipe-delimited format:
4|err|Page not found
Category may be used to use different colors for the messages. Categories are defined in npp.h:
#define MSG_CAT_OK "OK"
#define MSG_CAT_ERROR "err"
#define MSG_CAT_WARNING "war"
#define MSG_CAT_MESSAGE "msg"None
/* in npp_app_main */
int ret=OK;
if ( REQ("login") )
{
render_login();
}
else if ( REQ("do_login") ) /* via AJAX */
{
ret = npp_usr_login();
OUT_MSG_DESCRIPTION(ret);
}JSON version:
let x = new XMLHttpRequest();
// "do_login" request...
// ...
// when ready:
if ( x.responseText.length > 0 )
{
let r = JSON.parse(x.responseText);
if ( r.code != 0 ) // error -- show message
{
show_msg(r.message);
}
else // ok -- redirect
{
window.location.href = "dashboard";
}
}
else
{
show_msg("No response");
}Pipes version:
let x = new XMLHttpRequest();
// "do_login" request...
// ...
// when ready:
if ( x.responseText.length > 0 )
{
let r = x.responseText.split("|");
if ( r[0] != "0" ) // error -- show message
{
show_msg(r[2]);
}
else // ok -- redirect
{
window.location.href = "dashboard";
}
}
else
{
show_msg("No response");
}