为什么要重新加载页面而不是调用 ajax 函数?

发布于 2024-10-05 19:27:36 字数 356 浏览 0 评论 0原文

我有一个 javascript 函数,与表单上的提交相关联。当我单击链接时,页面会重新加载,并且该函数不会运行。我不确定可能导致此问题的原因,或者这是否是典型的错误行为。

javascript 代码是由另一个 ajax 调用动态生成的,但我认为这并不重要,因为代码位于页面上。但它没有执行。

(以下是上下文可能解释正在发生的情况的场景: 在列表中,每个项目都有一个显示选项链接。单击“显示选项”->运行 showoptions ajax 函数并生成 div 内容,其中包括指向 addoption 的链接,该链接运行 addoption ajax 函数(反过来应该重新运行 showoptions 来刷新列表,但我无法让它走那么远。当我单击“添加选项”。)

I have a javascript function, tied to a submit on a form. When I click the link, the page reloads and the function does not run. I'm not sure what might cause this or if it's typical error behaviour.

The code for the javascript is being generated dynamically by another ajax call, but I don't think that should matter, as the code is on the page. But it isn't executing.

(Here's the scenario in case context might explain what's happening:
In a list, each item has a show options link. click 'show options' -> runs showoptions ajax function and generates div contents, which include link to addoption, which runs addoption ajax function (which in turn should re-run showoptions to refresh the list, but I can't get it to go that far. It breaks when I click 'add option'.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

得不到的就毁灭 2024-10-12 19:27:37

有两种明显的可能性:

  1. JavaScript 中存在错误(将 JS 粘贴到 JS Fiddle 处的 JavaScript 框中,然后单击“JS” Lint' 按钮进行检查),或者
  2. 您的点击处理函数中缺少 return false(或 event.preventSefault)。

Edited to correct my typo. Oops.

There are two obvious possibilities:

  1. An error in your JavaScript (paste the JS into the JavaScript box at JS Fiddle and click the 'JS Lint' button to check), or
  2. You're missing a return false (or event.preventSefault) from your click-handling function.


Edited to correct my typo. Oops.

物价感观 2024-10-12 19:27:37

您的函数可能会出错,导致触发表单的默认行为。

查看错误控制台 - 您应该在那里获得更多详细信息。

Your function probably errors out, resulting in the form's default behaviour triggering.

Check out the error console - you should get some more details there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文