簡體   English   中英

在ajax調用完成后加載wordpress頁面

[英]Load wordpress page after an ajax call finish

我有一個對API的ajax調用,根據我想重定向用戶的響應,該API調用非常基礎,並且可以正常工作:

    jQuery(document).ready(function($){
      $.ajax({
        url: '//apicall-url',
        dataType: 'json',
        async: false,
        success: function(obj) {
           //redirect goes here
        }
      });
    }); 

我的問題是當前的wordpress頁面正在加載,並且一旦ajax調用“成功”就如何正確地進行此操作的任何建議(我是WP新手),都將進行重定向。

我也嘗試使用wp_enqueue_script函數,但得到了相同的結果。

我嘗試在標頭和正文中執行此操作,但沒有運氣。

您需要先進行api調用,然后才能加載頁面和腳本。 嘗試從PHP端調用您的API。 template_redirect鈎子。 這是創建重定向的最佳方法。

我的問題是等待Ajax調用更改的“文檔准備就緒”,這工作正常,這是我的代碼:

    (function($) { //<-This is an anonymous function that instantaneously runs.
      $.ajax({
        url: '//apicall-url',
        dataType: 'json',
        async: false,
        success: function(obj) {
          //redirect goes here
       }
      });
    })( jQuery );  //<----passing jquery to avoid any conflict with other libraries.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM