I am trying to use jquery.Ajax to send data to an ASP.NET MVC2 action method that returns JsonResult. Everything works fine, only when the response is returned to the browser, it is considered as downloading a file, and not passed to the success handler. Here is my code:
JavaScript:
<script type="text/javascript">
$(document).ready(function () {
$("form[action$='CreateEnvelope']").submit(function () {
$.ajax({
url: $(this).attr("action"),
type: "POST",
data: $(this).serialize(),
dataType: "json",
success: function (envelopeData) {
alert("test");
}
});
});
return false;
});
</script>
Controller action method:
public JsonResult CreateEnvelope(string envelopeTitle, string envelopeDescription)
{
return Json(envelope);
}
If I open the downloaded file, json is exactly what I'm looking for, and the mime type is displayed as application / json. What am I missing for the jquery.ajax call to get the returned json?
source
share