在成功函数angular js中显示错误

时间:2015-03-26 13:41:37

标签: angularjs error-handling

如何显示/记录json页面在成功函数中返回的错误?

当没有错误时,我将以下内容放入我的json页面

{"success":1,"error":"","recordcount":"1","fields":["Column1","Column2","Column3"],"data":[{"Column1":"0","Column2":"2015-03-26T00:00:00","Column3":""} ]}

如果必须发生错误

{"success":0,"error":" violation error","recordcount":"0","fields":[],"data":[ ]}

如果没有错误,它将显示self.show消息,如果返回错误,它必须是console.log或在网页上显示确切的错误 功能

  Get(self.$http,
            {
                url: Savedata,
                params: params,
                success: function (data)
                {

                    if (self.Save = data.data) {


                        self.Show = " saved."
                    }
                    else {
                        self.show = " ";
                    }
                    if (self.Save = data.error)
                    {
                        self.test= error //it should display the error from my json page                        }

                }
            }).error(function ()

            {

            });

1 个答案:

答案 0 :(得分:0)

结构错误

 success: function (data)
            {

                if (self.Save = data.data) {
                 self.Show = " saved."
                }
                else if(self.save==null)
                 {
                   self.show=data.error;
                 }

            }
        }).error(function ()