Logout Interface

The user logs out and clears the current login status and session information, supporting the return of HTML pages or JSON data format.

Precautions

  • This interface uses the GET method
  • Need to provide a random string to prevent interface caching
  • Supports returning HTML page or JSON data format
  • After logging out, the user session information will be cleared
  • Applicable to the website front-end user logout function

Request address

{域名地址}/logout

Description:{域名地址}Need to replace it with your domain address, such ashttps://en.anqicms.com/logout

Request syntax

GET {域名地址}/logout

Request Parameters

Field Name Type Required Description
return string No Support: html
nonce string Yes Random string, to prevent the interface from being cached

Return parameters

The returned content is different according to the request parameters:

  • Whenreturn=jsonauto, returns JSON format data:

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

Example Usage

JSON format return request example

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

JSON format return response example

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

HTML format return request example

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

HTML Format Response Example

HTTP/1.1 302 Found
Location: /

Front-end JavaScript Call Example

// 退出登录并返回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 Unauthorized
200 API request OK