1

I have the following code in html, I cannot get the Function call back of JSON get call. Down is the code in controller. Please Help

 <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);

            }
        }
4
  • 1
    What is the error or exception? Commented Mar 8, 2010 at 12:44
  • I dont get an error or exception, I just down not call the funtion Commented Mar 8, 2010 at 13:13
  • Then the problem is probably the routes. Use firebugs "net" tab to confirm that (or you will see the error instead). Commented Mar 8, 2010 at 13:14
  • If I use this function finished(txt) { $.getJSON('<%= ResolveUrl("~/Documentacion/GetDatosDespachantes")%>', { cuitDespachante: txt }, $('#nombreDespachante').html("Prueba")); } I see the html change Commented Mar 8, 2010 at 13:23

1 Answer 1

7

I have to add this in the response of the controller, Something new in ASP.NET MVC 2

 return Json(respuesta,JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

1 Comment

thx for this information. god, am i happy i found your answear.. i tried so long and never got a response back ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.