jQuery加载一直有效,直到我重新启动Wampserver,然后再没有了 [英] Jquery load is working till I restart Wampserver, and then not anymore

查看:70
本文介绍了jQuery加载一直有效,直到我重新启动Wampserver,然后再没有了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Jquery .load(),我尝试在Wordpress上加载一些内容.有时,当我的代码正常时,第二天就不再起作用了.

I try to have some content loaded on Wordpress thanks to Jquery .load(). Sometimes, when my code is OK, it's not working anymore the day after...

我正在尝试缩小原因.首先,我认为这是语法问题或单引号/双引号混合使用,但是由于它曾经工作过,因此没有理由涉及语法或错误. 我想到了错误的缓存设置,但shift + F5不会破坏我的工作代码.

I'm trying to narrow the causes. First I thought it was a syntax problem or a single/double quote mix up, but since it worked once, there is no reason syntax or error is involved. I thought about bad cache settings but shift+F5 won't break my working code.

现在,我刚刚尝试使用完美的代码来关闭并重新启动WAMPserver.宾果游戏,当我重新启动服务器时,无法使我的加载功能正常工作(从1分钟前开始……)!

And now I just tried, with a perfectly working code, to close and restart WAMPserver. And Bingo, when I restart the server it's impossible to get my load function to work (the same from 1 min before...) !

编辑:我刚刚用下面的代码替换了下面的代码

I just replaced the code (below) with the one I'm using now

$(document).ready(function(){
    $.ajaxSetup({cache:false});
    $("#portfolio-list li:not(#DrawerContainer)").click(function(){
        var post_link = $(this)
             //.parentsUntil(".ProjectWrap") 
             //.parent()
             .find('.mosaic-backdrop')
             .attr("href");
    console.debug(post_link); //to get post_link info in the console
    $('#DrawerContainer').remove(); // remove existing, if any
    $('<li/>').attr('id', 'DrawerContainer').css({display: 'none'}).data('citem', this).html("loading...").load(post_link + " #container > * ").insertAfter(LastInRow).slideDown(500);
    return false; 
    });
});

当该功能无法正常工作时,我尝试删除部分.load(post_link + " #container > * ");,并在紧随其后的部分(完整的URL)中将其替换.通常它可以正常工作,至少我可以继续设置页面样式,但是我必须解决问题.

When the function isn't working, I try to remove the part .load(post_link + " #container > * "); and replace it with the part just after (a complete url). Usually it works and at least I can continue styling my page, but I have to fix the problem.

什么会导致这种奇怪的行为? WAMPserver可以在关闭时重写某些内容吗? 我可以检查一个选项吗?

What can cause this weird behavior? Can WAMPserver rewrite something while closing? Is there an option I could check?

推荐答案

尽管已在问题的注释中解决了此问题,但这是任何浏览页面的人的答案.

Although this was solved in the question's comments, here is an answer for anybody skimming the page.

在不同域中运行ajax请求存在问题.您的WAMPserver不喜欢它,并且会停止运行,除非您另行通知.尽管您在本地工作,但WAMPserver认为http://localhost/http://127.0.0.1/不同.

There is an issue with running ajax requests across different domains. Your WAMPserver does not like it and will stop it unless you tell it otherwise. Although you are working locally, WAMPserver thinks http://localhost/ is different to http://127.0.0.1/.

要解决此问题,请在处理ajax的文件中添加以下内容:
<?php header('Access-Control-Allow-Origin: *'); ?>

To get around this, in the file that handles your ajax add this:
<?php header('Access-Control-Allow-Origin: *'); ?>

注意,您也可以更改URL的*(例如http://127.0.0.1/

Note, you can change the * for a URL too (e.g. http://127.0.0.1/

如果这不起作用,则可能必须更改服务器上的设置.

If that does not work, you may have to change settings on your server.

这篇关于jQuery加载一直有效,直到我重新启动Wampserver,然后再没有了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆