Javascript运行时错误json未定义 [英] Javascript runtime error json is undefined

查看:382
本文介绍了Javascript运行时错误json未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手,我创建了忘记密码的屏幕,

我想从用户在用户名文本框中输入的用户名中获取EmailId。



但我收到错误Javascript运行时错误Json未定义



我尝试过:



I am new in MVC,I have created forgot password screen,
I want to fetch EmailId from Username entered in Username textbox by user.

But i am getting error Javascript runtime error Json is undefined

What I have tried:

<script src="/Scripts/json2.js"></script>
<script src="/Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#UserName").change(function () {
            $.ajax({
                Type:"GET/POST",
                ContentType:"application/json;charset=utf-8",
                url:'/Login/GetEmail?UserId=0&IsEnabled=False&RoleId=0&Status=False',
                data:{allData : Json.Stringify(Model)},
                dataType:"json",
                success: function(data){
                    //alert(data.property1 + data.property2 );
                    if (data == null) {
                        alert('User Id not available')
                    }
                    else if (data.EmailId == null || data.EmailId == "") {
                        alert('Email Id not available');
                    }
                    else {
                        $("#EmailId").val("");
                    }
                },
                error: function(){
                    alert("Error");
                }
            });
        });
    });
</script>





控制器中的动作



Action in controller

public User GetEmail(User u)
{
    List<User> uList = gc.Users.Include(p => p.Role).Where(p => p.UserName == u.UserName).ToList();
    return u;
}

推荐答案

(document).ready(function(){
(document).ready(function(){


(#UserName)。change(function(){
("#UserName").change(function () {


.ajax({
类型:GET / POST,
ContentType: application / json; charset = utf-8,
url:'/ Login / GetEmail?UserId = 0& IsEnabled = False& RoleId = 0& Status = False',
data:{allData: Json.Stringify(Model)},
dataType:json,
success:function(data){
//alert(data.property1 + data.property2);
if(data == null){
alert('User Id not available')
}
else if(data.EmailId == null || data.EmailId ==){
alert('电子邮件ID不可用');
}
else {
.ajax({ Type:"GET/POST", ContentType:"application/json;charset=utf-8", url:'/Login/GetEmail?UserId=0&IsEnabled=False&RoleId=0&Status=False', data:{allData : Json.Stringify(Model)}, dataType:"json", success: function(data){ //alert(data.property1 + data.property2 ); if (data == null) { alert('User Id not available') } else if (data.EmailId == null || data.EmailId == "") { alert('Email Id not available'); } else {


这篇关于Javascript运行时错误json未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆