使用ASP.NET MVC在jquery中调用getJSON时出错

Jed*_*oky 1 asp.net-mvc jquery

我在html中有以下代码,我无法获得JSON调用的函数回调.Down是控制器中的代码.请帮忙

 <script type="text/javascript"> 
     $().ready(function() {
         $("#CuitDespachante").typeWatch({ highlight: true, wait: 500, captureLength: -1, callback: finished });
    });

    function finished(txt) {
        $.getJSON('/Documentacion/GetDatosDespachantes', { cuitDespachante: txt },
                            function (data) {
                                alert('You typed: ');
                            }
        );

    };
</script>

public ActionResult GetDatosDespachantes(string cuitDespachante)
        {
            cuitDespachante = cuitDespachante.Replace("-", "").Replace("_", "");
            DepositarioFielWS.DepositarioFielWebService ws = new DepositarioFielWS.DepositarioFielWebService();
            var res = ws.GetDespachante(cuitDespachante);
            if (res.Licencia.CodigoLicencia == DepositarioFielWS.CodigoLicencia.Ok)
            {
                DepositarioFielWS.Despachante desp = new DepositarioFielWS.Despachante();
                desp.Cuit = res.Despachante.Cuit;
                desp.Nombre = res.Despachante.Nombre;


                var respuesta  =new
                {
                    cuit = desp.Cuit,
                    nombre = desp.Nombre

                };
                return Json(respuesta);
            }
            else
            {
                var respuesta = new
                {
                    cuit = cuitDespachante,
                    nombre = "Imposible Realizar Consulta"

                };
                return Json(respuesta);

            }
        }
Run Code Online (Sandbox Code Playgroud)

Jed*_*oky 7

我必须在控制器的响应中添加它,ASP.NET MVC 2中的新功能

 return Json(respuesta,JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)