为什么要重新加载页面而不是调用 ajax 函数?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种明显的可能性:
return false
(或event.preventSefault
)。Edited to correct my typo. Oops.
There are two obvious possibilities:
return false
(orevent.preventSefault
) from your click-handling function.Edited to correct my typo. Oops.
您的函数可能会出错,导致触发表单的默认行为。
查看错误控制台 - 您应该在那里获得更多详细信息。
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.