1

I've looked at the previously-posted jQuery/MVC questions and haven't found a workable answer.

I have the following JavaScript code:

appCode.runReports = function (e) {

    var reportList = '';

    $('.rptCheck:checked').each(function (index) {
        reportList += ($(this).attr('reportName') + ',');
    });

    $.ajax({
            url: '/Report/RunReports/?reports=' + reportList,
            error: appCode.reportAjaxFailure,
            success: appCode.listRunningReports,
            complete: appCode.ajaxComplete,
            dataType: 'json'
        });

    e.preventDefault();
}

$(document).ready(function () {
    $('#runReportsButton').click(appCode.runReports);
});

The URL it calls into uses the following controller:

namespace workflowDemoMVC.Controllers
{
    public class ReportController : Controller
    {

        public JsonResult RunReports(string reports = "")
        {
            try
            {
                var ret = reports.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                return Json(ret, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                ide.Trace.WriteLine(ex.ToString());
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }

    }
}

When I run the code in dev, the controller action executes as expected and returns, but none of the callbacks defined in the AJAX call (complete, error, or success) fire. Once, in an earlier code version, I saw an 500-coded exception (Internal Server Error,) but now I don't see anything at all.

Environment: MVC3, jQuery1.6 .net4

4
  • jekke - i know you haven't mentioned it, but what does firebug report on running the code? Commented Jan 6, 2012 at 15:49
  • What do you see in FireBug console or the javascript developer toolbar you are using? Error? Is the AJAX request being sent? What does the server respond with? Commented Jan 6, 2012 at 15:49
  • 2
    guess we all agree on that then :) Commented Jan 6, 2012 at 15:50
  • Actually, it works fine in Firefox, so Firebug doesn't say much of anything. This turns out to be an IE-only bug. Commented Jan 6, 2012 at 17:23

1 Answer 1

2

You should try and set the content type on the AJAX call. I had a problem like this and that fixed it for me. Basically you would do this. I know I had a lot of problems with IE until I specified this.

$.ajax({
        url: '/Report/RunReports/?reports=' + reportList,
        error: appCode.reportAjaxFailure,
        success: appCode.listRunningReports,
        complete: appCode.ajaxComplete,
        dataType: 'json',
        contentType: 'application/json; charset=utf-8'
    });
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't seem to fix the problem, but it's still a good idea. Upvote.
Thank you for the up vote. Sorry that didn't fix the problem though. Have you tried doing it with async turned off? If not it may help to find the problem. Other than that I am not really sure what to do with out the error from firebug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.