Reputation: 5819
I code a .getJSon, It does the job but I get IE to asked to download the file. Here is the code
<script type="text/javascript">
$(function() {
$('#id').click(function() {
var dateReport = "01/01/2009";
$.getJSON('/Report/SendReport', { date: dateReport},
function(response) {
if (response.result == "OK") {
$('#OKSendReport').toggle();
$('#OKSendReport').html("OK");
}
});
});
});
The code in the controller is
public ActionResult SendReport(string date) {
//DO Stuff
return new JsonResult {
Data = new { result = "OK" }
};
}
Any ideas?
Upvotes: 1
Views: 1287
Reputation: 5976
Hmm Are you sure that the Javascript is being triggered in that instance? What is HTML type is #ID? If the JavaScript is not getting called and your controller is trying to route to the json result, I think that could be your problem.
Upvotes: 0
Reputation: 29267
Try adding the event.preventDefault();
on the click event:
$(function() {
$('#id').click(function(event) {
var dateReport = "01/01/2009";
event.preventDefault(); // added this
$.getJSON('/Report/SendReport', { date: dateReport},
function(response) {
if (response.result == "OK") {
$('#OKSendReport').toggle();
$('#OKSendReport').html("OK");
}
});
});
});
Upvotes: 2