0
 var jqopt = new jQueryAjaxOptions
            {
                Url = Model.Helper.ServiceEndpoint,
                Type = "Get"
            };

 var req = jQuery.Ajax(jqopt);
            req.Success(_ => { Log("Ajax succeeded: " + _.ToString()); });
            req.Fail(_ => { Log("Calling back after failure!!" + _.ToString()); });

我需要在错误中看到错误消息而不是 object _

4

1 回答 1

0

这是成功和错误回调的签名

  private void jsSuccessCallBack(object data, string textStatus, jQueryXmlHttpRequest request)
        {

            var items = data as List<FamilyTrustBE>;
            foreach (FamilyTrustBE item in items)
            {
                Helper.Log(string.Format("Result is: id {0}, {1}: {2}", item.id, item.name, item.description));
            }

        }

        private void jsErrorCallBack(jQueryXmlHttpRequest request, string textStatus, Exception error)
        {
            dynamic myerr = error;
            Helper.Log(string.Format("status={0} in ERROR callback. Error: {1}, Inner: {2}", textStatus, myerr.message, myerr.InnerException));
        }

这是我的 Helper.Log 方法:

    [IgnoreNamespace]
internal class Helper
{ 
    public static void Log(string str)
    {
        var content = jQuery.Select(Helper.HTMLMessageDivSelector).GetHtml();
        var messageDiv = jQuery.Select(Helper.HTMLMessageDivSelector);
        messageDiv.Html(str + "<br/>" + content);

        //write message to debug console if it is defined
        dynamic w = System.Html.Window.Self;
        { 
                if (w.console is object)   
                    w.console.log(str);
        }

    }
 }
于 2013-01-21T12:20:33.070 回答