问题描述
大家好,
我再次需要您的帮助.我已经完成了我的MVC Web应用程序的部署.但我遇到另一个问题.我的ajax无效.我的JavaScript里面的ajax.请参见下面的代码.
Hi guys,
again i need your help. i''m done deploying my MVC web application. but i have another problem encounter. my ajax did not work. my ajax inside my javascript. please see below code.
<script type="text/javascript">
$(document).ready(function () {
$(''#btnLogin'').click(function () {
var tmplogin = { "tmpUName": "", "tmpPword": "" };
tmplogin.tmpUName = document.getElementById(''txtUserID'').value;
tmplogin.tmpPword = document.getElementById(''txtUserPassword'').value;
$.ajax({
url: ''/Home/Verify'',
data: JSON.stringify(tmplogin),
type: ''POST'',
contentType: ''application/json;'',
dataType: ''json'',
success: function (result) {
if (result.Success != 0) {
window.location.href = "/AdminPage/Index"
}
else {
alert(result.ex);
};
}
});
});
});
</script>
我的控制器是:
and my controller is:
[HttpPost]
public JsonResult Verify(string tmpUName, string tmpPword)
{
try
{
return Json(new { Success = 0, ex = "Success" });
}
catch (Exception ex)
{
return Json(new { Success = 0, ex = ex.Message.ToString() });
}
}
就这么简单..但它不会返回任何消息.
我认为问题出在ajax中,因为当我尝试在
之后放置警告消息时
as simple as that.. yet it won''t return any message.
i would believe that problem is in ajax because when i try to put an alert message after
tmplogin.tmpUName = document.getElementById('txtUserID').value;
tmplogin.tmpPword = document.getElementById('txtUserPassword').value;
alert("alert");
警报消息将弹出.
任何想法如何解决这个问题?我的参考文件上需要添加任何dll或文件吗?
在此先感谢.
-naijeru-
the alert messge will pop-up.
any idea how to resolve this? is there any dll or files needed to add on my reference?
thanks in advance.
-naijeru-
推荐答案
我的控制器是:
and my controller is:
[HttpPost]
public JsonResult Verify(string tmpUName, string tmpPword)
{
try
{
return Json(new { Success = 0, ex = "Success" });
}
catch (Exception ex)
{
return Json(new { Success = 0, ex = ex.Message.ToString() });
}
}
就这么简单..但它不会返回任何消息.
我认为问题出在ajax中,因为当我尝试在
之后放置警告消息时
as simple as that.. yet it won''t return any message.
i would believe that problem is in ajax because when i try to put an alert message after
tmplogin.tmpUName = document.getElementById('txtUserID').value;
tmplogin.tmpPword = document.getElementById('txtUserPassword').value;
alert("alert");
警报消息将弹出.
任何想法如何解决这个问题?我的参考文件上需要添加任何dll或文件吗?
在此先感谢.
-naijeru-
the alert messge will pop-up.
any idea how to resolve this? is there any dll or files needed to add on my reference?
thanks in advance.
-naijeru-
这篇关于大家好,来自noob程序员的另一个问题:关于ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!