<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                Heartbeat API是一種內置于WordPress的簡單服務器輪詢API,可實現近實時前端更新。 ## 怎么運行的 當頁面加載時,客戶端心跳代碼設置一個間隔(稱為“tick”),每15-60秒運行一次。 當它運行時,心跳收集要通過jQuery事件發送的數據,然后將其發送到服務器并等待響應。 在服務器上,一個admin-ajax處理程序將傳遞的數據,準備一個響應,過濾響應,然后以JSON格式返回數據。 客戶端接收這些數據,并觸發一個最終的jQuery事件來指示數據已被接收。 自定義心跳事件的基本過程是: - 向要發送的數據添加其他字段(JS心跳發送事件) - 檢測PHP中發送的字段,并添加其他響應字段(heartbeat_received過濾器) - 處理返回的數據在JS(JS heartbeat-tick) (您可以選擇僅使用一個或兩個這些事件,具體取決于您需要的功能。) ## 使用API 使用心跳API需要兩個獨立的功能:在JavaScript中發送和接收回調,以及服務器端過濾器來處理PHP中傳遞的數據。 ## 發送數據到服務器 當心跳發送數據到服務器時,您可以包括自定義數據。 這可以是要發送到服務器的任何數據,也可以是一個簡單的真實值,表示您期望數據。 ``` jQuery( document ).on( 'heartbeat-send', function ( event, data ) { // Add additional data to Heartbeat data. data.myplugin_customfield = 'some_data'; }); ``` ## 在服務器上接收和響應 在服務器端,您可以檢測此數據,并向響應中添加其他數據。 ``` // Add filter to receive hook, and specify we need 2 parameters. add_filter( 'heartbeat_received', 'myplugin_receive_heartbeat', 10, 2 ); /** * Receive Heartbeat data and respond. * * Processes data received via a Heartbeat request, and returns additional data to pass back to the front end. * * @param array $response Heartbeat response data to pass back to front end. * @param array $data Data received from the front end (unslashed). */ function myplugin_receive_heartbeat( $response, $data ) { // If we didn't receive our data, don't send any back. if ( empty( $data['myplugin_customfield'] ) ) { return $response; } // Calculate our data and pass it back. For this example, we'll hash it. $received_data = $data['myplugin_customfield']; $response['myplugin_customfield_hashed'] = sha1( $received_data ); return $response; } ``` ## 處理響應 返回到前端,然后可以處理接收到的數據。 ``` jQuery( document ).on( 'heartbeat-tick', function ( event, data ) { // Check for our data, and use it. if ( ! data.myplugin_customfield_hashed ) { return; } alert( 'The hash is ' + data.myplugin_customfield_hashed ); }); ``` 并不是每個功能都需要這三個步驟。 例如,如果您不需要將任何數據發送到服務器,則可以僅使用后兩個步驟。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看