views:

46

answers:

1

Hi Guys

I have the following $.post() function that expects JSON as its return value.

$.post($(this).attr("action"), $(this).serialize(), function(data)
{
    if (data.returnData)
    {
        //do stuff with data.returnData
    }

}, "json");

This piece of code does the trick so long as the return type is JSON.

The question I have though, is whether it's possible to dynamically determine/specify the return type? The reason for this is that I have ActionMethods that could return Json or some other datatype (e.g. html or a redirect), and this $.post() function fails unless it's JSON.

Any suggestions?

Thanks

Dave

+1  A: 

You could use $.ajax instead of the simpler $.post, and then figure out what the response body is with your own code.

Pointy
DaveDev