如何使用ajax创建单击按钮 [英] How do I make a click button with ajax
本文介绍了如何使用ajax创建单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看过几次视频了。出于某种原因,我无法弄清楚如何用Ajax制作一个单词按钮Hello Ajax。
这是我对/ Home / Index的看法:
@ {
Layout = null;
}
< !DOCTYPE html >
< html >
< head >
< script src = 〜/ Scripts / jquery-1.10.2.js > < / < span class =code-leadattribute> script >
< script src = 〜/ Scripts / jquery.unobtrusive-ajax.min.js > < / script >
< script >
$( document )。ready( function (){
$( button).click( function (){
$ ajax({
type:' GET',
url:' @ Url.Action(HelloAjax,Home)',
成功:功能(结果){
(' #DIV1' 跨度>)HTML(结果);
}
}); // 关闭ajax
}); // 关闭点击功能
}); // 关闭文档就绪功能
< / script >
< title > 人口动态研究< / title >
< / head >
< 正文 >
< div id = div1 > < h2 > 让jQuery AJAX更改此文本< / h2 > < / div > ;
< 按钮 > 获取外部内容< / button >
< / body >
< / html >
我尝试过:
AJAX in ASP.NET MVC - YouTube [ ^ ]
解决方案
( document )。ready( function (){
( button)。 click( function (){
ajax({
type:' GET',
url:' @ Url.Action(HelloAjax,Home)',
成功: function (结果t){
(' #div1')。html(result) ;
}
}); // 关闭ajax
}); // 关闭点击功能
}); // 关闭文档就绪功能
< / script >
< title > 人口动态研究< / title >
< / head >
< 正文 >
< div id = div1 > < h2 > 让jQuery AJAX更改此文本< / h2 > < / div > ;
< 按钮 > 获取外部内容< / button >
< / body >
< / html >
我尝试过:
AJAX in ASP.NET MVC - YouTube [ ^ ]
I have watched the video a couple times. For some reason, I just cannot figure out how to make a click button that says "Hello Ajax" with Ajax.
Here is my view for /Home/Index:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$ajax({
type: 'GET',
url: '@Url.Action("HelloAjax" , "Home")',
success: function (result) {
('#div1').html(result);
}
}); // closes the ajax
}); // closes click function
}); // closes document ready function
</script>
<title>A study of population dynamics</title>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
What I have tried:
AJAX in ASP.NET MVC - YouTube[^]
解决方案
(document).ready(function () {
("button").click(function () {
ajax({ type: 'GET', url: '@Url.Action("HelloAjax" , "Home")', success: function (result) { ('#div1').html(result); } }); // closes the ajax }); // closes click function }); // closes document ready function </script> <title>A study of population dynamics</title> </head> <body> <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> <button>Get External Content</button> </body> </html>
What I have tried:
AJAX in ASP.NET MVC - YouTube[^]
这篇关于如何使用ajax创建单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文