【发布时间】:2015-02-22 11:05:01
【问题描述】:
我有这个 html 表单,我需要从控制器获取一些结果(如布尔结果)...... 这就是我的表单的样子......
<div id="temp"></div>
@using (Html.BeginForm("Result", "Home"))
{
@Html.TextBox("str")
<input type="submit" value="Submit" id="submit">
}
这就是我的 Get Method 和 Post Method 在控制器中的样子......
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string str)
{
bool res = true;
if(str == "Jude")
res=true;
Return View(res);
}
所以现在我需要做的是,我需要检查结果是真还是假,并从 html 页面给用户一个确认........
<script>
$('#submit').click(function () {
alert("hello");
$.get("../Home/Index", function (data) {
var res = html(data);
if (res == true)
$('#temp').replaceWith("Success");
else
$('#temp').replaceWith("Some Thing Went Wrong!!");
});
//$.ajax({
// type: "GET",
// url: "../Home/Index",
// data: data,
// success: function (data)
// {
// $('#temp').append("hello");
// },
// dataType: dataType
//});
});
</script>
请告诉我如何解决这个问题....... 谢谢!!!!
【问题讨论】:
标签: javascript jquery ajax jquery-ui javascript-events