Ton*_*nyc 15 javascript ajax asp.net-mvc asp.net-core
我正在尝试使用标签data-*实现Ajax调用,如 jquery-ajax-unobtrusive所述
我知道我可以使用$ .ajax()的javascript函数,但我的目的是试验标签data-ajax ...
我在cshtml文件中尝试了这段代码
<a class="btn btn-primary" data-ajax-url="/Home/AjaxSample" data-ajax="true" data-ajax-success="AjaxSuccess" data-ajax-failure="AjaxError" data-ajax-method="GET">Ajax</a>
// other code...
function AjaxSuccess() { alert('AjaxSuccess'); }
function AjaxError() { alert('AjaxError'); }
Run Code Online (Sandbox Code Playgroud)
浏览器当然会显示按钮,但单击它时没有任何反应.我无法在浏览器调试器中发现任何错误.显然没有任何事情发生.
Intellisense不显示标签data-ajax和friends.我忘了包含一些东西吗?
有没有完整的工作实例?
评论中的答案(因为没有人添加):
\n\n<script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.j\xe2\x80\x8c\xe2\x80\x8bs"></script>\n<!-- the ~ is to symbolize your project\'s wwwroot folder\nRun Code Online (Sandbox Code Playgroud)\n\n将以上内容与所有其他脚本一起添加到您的主布局中(_Layout.cshtml默认情况下)。
其作用是将 jQuery 不显眼的 ajax 文件包含到所有页面中,以便包含完成所有工作的主脚本。
\n\n执行此操作之前,请确保您已安装该软件包Microsoft.Jquery.Unobtrusive.Ajax
| 归档时间: |
|
| 查看次数: |
2591 次 |
| 最近记录: |