简体   繁体   English

奇怪的Javascript行为-移植到WordPress

[英]Odd Javascript behavior - porting to WordPress

I'm currently making my first effort into porting a webpage to Wordpress, so forgive my inexperience on the subject. 我目前正在尽力将网页移植到Wordpress,因此请原谅我对此方面的经验。

In my page, I have the following code: 在我的页面中,我有以下代码:

function workLoad() {

  $.ajaxSetup({ cache: false });

  $('.thumb-unit').click(function() {

    var $this = $(this),
        newTitle = $this.find('strong').text(),
        newFolder = $this.data('folder'),
        spinner = 'Loading...',
        newHTML = 'work/'+ newFolder +'.html';
    $('.project-load').html(spinner).load(newHTML);
    $('.project-title').text(newTitle);


  });

}

In the past, this has worked fine hosted both locally and on Github. 过去,在本地和Github上托管都很好。 However, running my wordpress build locally through MAMP gives me the following error: 但是,通过MAMP在本地运行wordpress构建会出现以下错误:

jquery-2.1.1.min.js:4 GET http://localhost/work/proj-1.html?_=1485348127113 404 (Not Found)

The URL should be fine, except for the part where it adds the ?_=(number). 该URL应该很好,除了它添加?_ =(number)的部分。 I'm not familiar with this behavior or what causes it. 我不熟悉此行为或其原因。 I tried changing work/ to /work/, since the dir is in the root folder, but that didn't solve it. 我尝试将work /更改为/ work /,因为该目录位于根文件夹中,但是并不能解决问题。 I also have tried changing the variable to newHTML = '< ?php bloginfo('template_directory')' + '/work/'+ newFolder +'.html'; 我也尝试将变量更改为newHTML = '< ?php bloginfo('template_directory')' + '/work/'+ newFolder +'.html'; without the space after the opening bracket but to no avail. 开括号后没有空格,但无济于事。 I also tried putting that bit in its own var, but it keeps adding ?_=1485348127113 to the URL of the html file I want to load, resulting in a 404 error. 我也尝试将其放在自己的var中,但它一直向我要加载的html文件的URL中添加?_=1485348127113 ,导致404错误。

What causes this? 是什么原因造成的? Thanks in advance for any advice you could share. 预先感谢您可以分享的任何建议。

This timestamp is added for You to obtain the latest version of the file using ajax load. 为您添加了此时间戳,以便您使用ajax加载获取文件的最新版本。 If You want to disable this behaviour, You should set 如果要禁用此行为,则应设置

$.ajaxSetup({
    cache: true
});

This will enable caching and Your request would not contain the ?_=1485348127113 part anymore. 这将启用缓存,并且您的请求将不再包含?_=1485348127113部分。 This parameter should not cause the 404 not found error. 此参数不应导致404 not found错误。 Please check your path. 请检查您的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM