Log out interface

User logs out, clears the current login status and session information, supports returning HTML page or JSON data format.

Points to note

  • This interface uses the GET method
  • Provide a random string to prevent the interface from being cached
  • Supports returning HTML pages or JSON data format
  • After logging out, the user session information will be cleared
  • Suitable for website front-end user logout function

Request address

{域名地址}/logout

Description:{域名地址}Replace it with your domain name, such ashttps://en.anqicms.com/logout

Request Syntax

GET {域名地址}/logout

Request parameters

Field name Type Required Description
return string No Support: html
nonce string Is Random string to prevent interface from being cached

Return parameters

The returned content is different according to the request parameters:

  • Whenreturn=jsonAt time, return JSON data format:

    • code: int - Error code
    • msg: string - Error description
  • Whenreturn=htmlor not specified, return HTML page content

Usage Example

JSON format returns request example

GET /logout?return=json&nonce=1234567890 HTTP/1.1
Host: www.anqicms.com

JSON format returns response example

{
  "code": 0,
  "msg": "退出成功"
}

HTML format returns request example

GET /logout?nonce=0987654321 HTTP/1.1
Host: www.anqicms.com

Example of response returned in HTML format

HTTP/1.1 302 Found
Location: /

Example of calling front-end JavaScript

// 退出登录并返回JSON结果
$.get("/logout", {
  return: "json",
  nonce: Date.now()
}, function(res) {
  if (res.code === 0) {
    console.log('退出成功');
    window.location.href = '/'; // 跳转到首页
  } else {
    console.error('退出失败', res.msg);
  }
}, 'json');

// 直接跳转退出(HTML返回)
function logout() {
  window.location.href = '/logout?nonce=' + Date.now();
}

error code

Error code Description
0 OK
-1 Error, the reason is indicated in msg
1001 Not logged in
1002 Not authorized
200 API request OK