2010-03-08 48 views
1

我在html中有以下代码,我无法获取JSON获取调用的函数回调。向下是控制器中的代码。请帮助jQuery与ASP.NET MVC中的getJSON调用时出现错误

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

      } 
     } 
+1

什么是错误或异常? – 2010-03-08 12:44:25

+0

我没有得到一个错误或异常,我只是没有调用函数 – 2010-03-08 13:13:09

+0

然后问题可能是路线。使用萤火虫“净”标签来确认(或者你会看到错误)。 – 2010-03-08 13:14:14

回答

7

我不得不在控制器的响应添加此,在ASP.NET MVC新的东西2

return Json(respuesta,JsonRequestBehavior.AllowGet); 
+1

thx。上帝,我很高兴我发现你的答案..我试了这么久,从来没有得到回应;-) – SQueek 2010-05-07 15:49:01

相关问题