开发者

Determining URL path for AJAX file loading in WordPress

开发者 https://www.devze.com 2023-03-11 18:16 出处:网络
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.

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.

How do I dynamically establish my home path no matter what page I'm on? (I don't w开发者_运维问答ant to hardcode the full URL)

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

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


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
});


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

the "/" do the trick

0

精彩评论

暂无评论...
验证码 换一张
取 消