开发者

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.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜