如何使用jquery ajax()回调后获取一些值 [英] how to get some value after the callback comes using jquery ajax()

查看:78
本文介绍了如何使用jquery ajax()回调后获取一些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的专家,

在mvc3-i中,我希望某些东西在后台执行,并且其回调再次返回到同一页面,得到2件事-"Exception"& 成功".为此,我正在使用Ajax()-

Dear Experts,

In mvc3-i want some stuff to be perform in background and its callback comes again to the same page getting 2 things-"Exception" & "IsSuccessfull". For that i am using Ajax()-

$.ajax({
                        url: '//localhost:1787/Table/Index/',
                        type: "POST",
                        data: JSON.stringify(tb),
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        async:true,
                        success: function (data) {
                            $('.result').html(data);
                            alert('success');
                        },
                        error: function () { alert("error"); }
                    });



此动作方法工作正常. TableModel有2个属性Error(类型异常)和IsSuccessfull(布尔),这些是我实际上想要的属性.因此,在ajax()的error function()中,我可以获得Error属性.怎么走,不知道?



This action method working fine. TableModel have 2 property Error(of type exception) and IsSuccessfull(bool),these are the properties which i actually want..so that in error function() of ajax() i can get the Error property. how to go,don''t know??

public ActionResult Index(TableModel tb)
        {
            string tablename = tb.TableName;
            TableModel tableModel = new TableModel();
            try
            {
               ....doning some stuff, getting the result in "var result".
               if (!result.IsOperationSuccessful)
               {
                   tableModel.Error=result.Error;
               }
            }
            catch (ArgumentNullException ex)
            {
                tableModel.Error = ex;
            }
            catch (ArgumentException ex)
            {
                tableModel.Error = ex;
            }
            return View(tableModel);
        }

推荐答案

.ajax({ 网址:' //localhost:1787/Table/Index/', 类型:" , 数据:JSON.stringify(tb), dataType:" , contentType:" 异步:, 成功:函数(数据){
.ajax({ url: '//localhost:1787/Table/Index/', type: "POST", data: JSON.stringify(tb), dataType: "json", contentType: "application/json; charset=utf-8", async:true, success: function (data) {


(' .result').html(数据); alert(' 成功'); }, 错误:function(){alert(" ); } });
('.result').html(data); alert('success'); }, error: function () { alert("error"); } });



此动作方法工作正常. TableModel有2个属性Error(类型异常)和IsSuccessfull(布尔),这些是我实际上想要的属性.因此,在ajax()的error function()中,我可以获得Error属性.怎么走,不知道?



This action method working fine. TableModel have 2 property Error(of type exception) and IsSuccessfull(bool),these are the properties which i actually want..so that in error function() of ajax() i can get the Error property. how to go,don''t know??

public ActionResult Index(TableModel tb)
        {
            string tablename = tb.TableName;
            TableModel tableModel = new TableModel();
            try
            {
               ....doning some stuff, getting the result in "var result".
               if (!result.IsOperationSuccessful)
               {
                   tableModel.Error=result.Error;
               }
            }
            catch (ArgumentNullException ex)
            {
                tableModel.Error = ex;
            }
            catch (ArgumentException ex)
            {
                tableModel.Error = ex;
            }
            return View(tableModel);
        }


您可以尝试这样

You can try like this


这篇关于如何使用jquery ajax()回调后获取一些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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