0

I have a simple $.ajax call that i did a million times before

$.ajax({
  type: "POST",
  url: url,
  data: data,              
  sucess: function (data) {
          alert(data);
          }
});

and a controller that accepts my data without a problem but i can't seem to return data to the sucess function.

[HttpPost]
public ActionResult MyAction(MyClass data)
{
   //do something
   return Content("blabla");           

}

What seems to be the problem?

EDIT: Everything was ok but i wrote sucess instead of success.

 $.ajax({
      type: "POST",
      url: url,
      data: data,              
      success: function (data) {
              alert(data);
              }
    });
Matija Grcic
  • 12,963
  • 6
  • 62
  • 90
  • Look this http://stackoverflow.com/questions/5980389/proper-way-to-use-ajax-post-in-jquery-to-pass-model-from-strongly-typed-mvc3-vie – mola10 Apr 11 '12 at 10:44

1 Answers1

0

It could be that you need to return a json-p style response... if the javascript and server side code are running on different domains then this is almost certainly the case. Take a looks at http://api.jquery.com/jQuery.ajax/ for some more details.

I suggest you try :

 $.ajax({
  type: "POST",
  datatype: "text",
  async: false,
  url: url,
  data: data,              
  sucess: function (data) {
          alert(data);
          }
});

The idea is if you ask for a synchronous call and request type of text then it should get around the jsonp / callback issue.

Hopefully worth a try :)

Dan Murphy
  • 548
  • 2
  • 13
  • thanks but the problem was in my tired eyes. I wrote sucess instead of success as you did too in the response, still thanks for looking at it. – Matija Grcic Apr 11 '12 at 11:41
  • Do'oh, sometime the simplest mistakes are the tough ones to spot. glad you got it working :) – Dan Murphy Apr 11 '12 at 15:17