Making an Ajax request to a page method in ASP.NET MVC 2

Posted by JLago on Stack Overflow See other posts from Stack Overflow or by JLago
Published on 2010-04-22T22:25:57Z Indexed on 2010/04/22 22:33 UTC
Read the original article Hit count: 382

I'm trying to call a page method belonging to a MVC Controller from another site, by means of:

$.ajax({
          type: "GET",
          url: "http://localhost:54953/Home/ola",
          data: "",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(data) {
                console.log(data.Name);
          }
        });

the method code is as follows, really simple, just to test:

 public ActionResult ola()
    {

        return Json(new ActionInfo()
        {
            Name = "ola"
        },JsonRequestBehavior.AllowGet);

    }

I've seen this aproach being suggested here, and I actually like it a lot, should it work...

When I run this, firebug gets a 200 OK, but the data received is null.

I've tried a lot of different approaches, like having the data in text (wish grants me "(an empty string)" instead of just "null") or returning string in the server method...

Can you tell me what am I doing wrong?

Thank you in advance,

João

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-ajax