hunter
hunter

Reputation: 63542

jQuery AJAX request bombs on EmptyResult

This is similar to this question but this did not solve my problem since this is exactly how I'm handling this.

    $("#code").live("change", function() {           
        var data = { codeId: $(this).find(":selected").attr("id") };

        $.ajax({
            type: "GET",
            url: codeUrl,
            data: data,
            success: function(html) {
               // never gets hit if EmptyResult();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
               // never gets hit until page navigation, which aborts this call
            }
        });
    });

    [HttpGet]
    public ActionResult CodeParameters(int codeId)
    {
        IList<AdjustmentParameter> parameters = GetCodeParameters(codeId);

        if (parameters == null || !parameters.Any())
            return new EmptyResult();

        return PartialView("EditorTemplates/AdjustmentParameters", parameters);
    }

Any code that returns HTML works as expected but any code that returns new EmptyResult() seems to break the ajax call. Should I be doing something differently? Strangely enough this does not happen on 3 different web servers, only on the public facing server (naturally).

Upvotes: 4

Views: 1723

Answers (1)

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

I ran into an issue in Fire Fox with an EmptyResult. Fixed when I specified the dataType: 'html' in the ajax options.

Upvotes: 6

Related Questions