简体   繁体   English

谁能告诉我为什么我的警报没有触发? 娜达(Zada)

[英]Can anyone tell me why my alert(id) isn't firing off? Nada, zilch, zippo

First of all let me say thank you to everyone that offered answers...I have definitely advanced and even on my local machine everything is working perfectly. 首先,我要向所有提供答案的人表示感谢...我肯定已经进步了,即使在我的本地计算机上,一切也都运转良好。

However it's not working on the server. 但是,它在服务器上不起作用。 I tried a bunch of things such as putting session_start() into the included files but nothing has taken. 我尝试了很多事情,例如将session_start()放入包含的文件中,但是什么也没做。

Rather than post the code here I've zipped up a few files: 我没有在这里发布代码,而是压缩了一些文件:

http://nerotic.net/aux/code.zip http://nerotic.net/aux/code.zip

and you can see the site at the same URL removing /code.zip 并且您可以在删除/code.zip的同一URL上看到该网站

index.php: has the AJAX in it... index_page_content.inc.php: is my file to determine which content gets included backend.php: the PHP to process the AJAX sound-how.php: one of the pages that gets included by index.php index.php:其中包含AJAX ... index_page_content.inc.php:是我的文件,用于确定要包含哪些内容backend.php:用于处理AJAX的PHP sound-how.php:被包含的页面之一通过index.php

The behavior is weird. 行为很奇怪。 It won't echo 'src' where I echo it, however it will display it where I'm echoing 'section'. 它不会在我回声的地方回显“ src”,但是会在我回声“ section”的地方显示它。 But as soon as I reload it goes back to echoing 'section' in the exact same place. 但是,只要我重新加载,它就会返回到在完全相同的地方回显“部分”的信息。

Also, in Chrome every couple of links that I click on makes the entire page reload. 另外,在Chrome浏览器中,我单击的每两个链接都会重新加载整个页面。

So if anyone can tell me what I'm doing wrong :) 所以如果有人可以告诉我我在做什么错:)

Thanks in advance. 提前致谢。

ORIGINAL POST 原始帖子

I'm new at PHP and relearning JS so any help would be appreciated. 我是PHP的新手,现在又在学习JS,因此可以提供任何帮助。

<script language="JavaScript"
type="text/javascript">

    $(document).ready(function() {

          $("div.tabs").tabs(".images > div", {

                // enable "cross-fading" effect
                effect: 'fade',
                fadeInSpeed: 600,
                fadeOutSpeed: 1000,

                // start from the beginning after the last tab
                rotate: false

              // use the slideshow plugin. It accepts its own> configuration
              }).slideshow({autoplay: false, interval:5000});


          $("a.lnav").onclick(function() {
                    // Get the ID of the link
                    var src = $(this).attr("id");
                    alert(id);

                    // Send Ajax request to backend.php, with src set as "id in> the POST data
                    $.post("/backend.php", {"id": src});
                });

          });  </script>

不仅仅是.click绑定事件,不是.onclick吗?

you probably meant to do alert(src); 您可能打算执行alert(src); , can't see any where in yout code where a variable id has a value assigned to it. ,在您的代码中看不到变量id分配了值的任何位置。

If you've pasted your code exactly as you set it up you're calling an non-existent method in jQuery. 如果您按照设置的正确粘贴了代码,则将在jQuery中调用不存在的方法。 You mean to be using $('a.lnav').click() . 您的意思是使用$('a.lnav').click()

 $("a.lnav").click(function() {
                // Get the ID of the link
                var src = $(this).attr("id");
                alert(src);

                // Send Ajax request to backend.php, with src set as "id in> the POST data
                $.post("backend.php", {id: src});
            });

You don't define id for alert(id); 您没有为alert(id);定义id alert(id); - would that throw an error rather than an alert? -这会引发错误而不是警报吗?

Is there an <a> tag with a class of lnav like <a class="lnav"> ? 是否有像<a class="lnav">这样的lnav类的<a>标记?

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

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