確定WordPress中加載AJAX文件的URL路徑

[英]Determining URL path for AJAX file loading in WordPress


I use the following code in my WordPress homepage template, and it works fine. However, when I try to use it in a page with a different path, it fails to find the file.

我在我的WordPress主頁模板中使用以下代碼,它工作正常。但是,當我嘗試在具有不同路徑的頁面中使用它時,它無法找到該文件。

How do I dynamically establish my home path no matter what page I'm on? (I don't want to hardcode the full URL)

無論我在哪個頁面,我如何動態建立我的家庭路徑? (我不想硬編碼完整的URL)

Works in mywordpress.com/ but not in mywordpress.com/page/ :

可在mywordpress.com/中使用,但不能在mywordpress.com/page/中使用:

// Initiate asynchronous load of xml data:
jQuery.ajax({
    type: "GET",
    url: "wp-content/themes/mytheme/data.xml",
    dataType: "xml",
    success: parseDataXML
});

2 个解决方案

#1


1  

Maybe an absolute url?

也許是一個絕對的網址?

// Initiate asynchronous load of xml data:
jQuery.ajax({
    type: "GET",
    url: "/wp-content/themes/mytheme/data.xml",
    dataType: "xml",
    success: parseDataXML
});

#2


0  

url: "/wp-content/themes/mytheme/data.xml",

the "/" do the trick

“/”做的伎倆


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/06/08/7256ee292fca5fc845554a58dcf2f798.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com