You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求修改Zajax WordPress插件以支持根相对URL

Fixing Zajax to Support Root-Relative URLs for Uninterrupted Audio Playback

Got it, let's get your Zajax plugin working with root-relative URLs so you don't have to manually swap to absolute URLs every time. Since the plugin is no longer updated, we'll modify its core JavaScript to recognize and handle root-relative paths correctly. Here's how to do it step by step:

  • Step 1: Locate the plugin's main JavaScript file
    Navigate to your WordPress plugins directory (wp-content/plugins/zajax/) and look for a js folder. Inside, you'll likely find a file like zajax.js, main.js, or frontend.js—this is where the AJAX URL handling logic lives. Make a backup of this file before editing, just in case.

  • Step 2: Find the URL validation logic
    Open the JS file and search for code that checks if a URL should be loaded via AJAX. You'll probably see something like this (or a variation using regex):

    // Example original code checking for absolute URLs
    if (url.startsWith('http') || url.startsWith('//')) {
        // Handle AJAX load
    } else {
        // Fallback to full page reload
    }
    

    The issue here is it only triggers AJAX for absolute URLs. We need to add root-relative URLs (those starting with /) to this condition.

  • Step 3: Update the URL check to include root-relative paths
    Modify the condition to include URLs that start with /:

    // Updated condition supporting root-relative URLs
    if (url.startsWith('http') || url.startsWith('//') || url.startsWith('/')) {
        // Handle AJAX load
    } else {
        // Fallback to full page reload
    }
    
  • Step 4: Convert root-relative URLs to absolute for AJAX requests (if needed)
    Some AJAX implementations require absolute URLs to work correctly. If the plugin's AJAX call fails with root-relative paths, add a quick conversion step right before the AJAX request:

    // Convert root-relative URL to absolute if needed
    if (url.startsWith('/')) {
        // Use your site's base URL (window.location.origin gets http(s)://yourdomain.com)
        const siteBase = window.location.origin;
        url = siteBase + url;
    }
    

    Alternatively, if WordPress has already defined a global site URL variable (like window.site_url), use that instead of window.location.origin for better accuracy.

  • Step 5: Test thoroughly
    Save your changes, then visit your site. Click on links using root-relative URLs (like /about or /contact)—they should load via AJAX now, and your streaming audio should keep playing without interruption. If something breaks, revert to your backup file and double-check the code edits.

Since the plugin is no longer maintained, your changes won't be overwritten by updates. Just keep a copy of the modified JS file somewhere safe in case you ever need to re-install the plugin.

内容的提问来源于stack exchange,提问作者gulliver

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:55:30