繁体   English   中英

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

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

首先,我要向所有提供答案的人表示感谢...我肯定已经进步了,即使在我的本地计算机上,一切也都运转良好。

但是,它在服务器上不起作用。 我尝试了很多事情,例如将session_start()放入包含的文件中,但是什么也没做。

我没有在这里发布代码,而是压缩了一些文件:

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

并且您可以在删除/code.zip的同一URL上看到该网站

index.php:其中包含AJAX ... index_page_content.inc.php:是我的文件,用于确定要包含哪些内容backend.php:用于处理AJAX的PHP sound-how.php:被包含的页面之一通过index.php

行为很奇怪。 它不会在我回声的地方回显“ src”,但是会在我回声“ section”的地方显示它。 但是,只要我重新加载,它就会返回到在完全相同的地方回显“部分”的信息。

另外,在Chrome浏览器中,我单击的每两个链接都会重新加载整个页面。

所以如果有人可以告诉我我在做什么错:)

提前致谢。

原始帖子

我是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吗?

您可能打算执行alert(src); ,在您的代码中看不到变量id分配了值的任何位置。

如果您按照设置的正确粘贴了代码,则将在jQuery中调用不存在的方法。 您的意思是使用$('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});
            });

您没有为alert(id);定义id alert(id); -这会引发错误而不是警报吗?

是否有像<a class="lnav">这样的lnav类的<a>标记?

暂无
暂无

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

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