سؤال

I am using the JQuery Form Plugin but having an issue with IE 11 where "data.Success" is coming back false eventhough there is JSON in the response as evidenced by tracing the network traffic with IE Developer Tools.

I am seeing a successful initial AJAX POST to /NewClubOpeningTool/ProcessCompose/ with a hydrated JSON response, yet data.Success is false.

Response:

{"Success":true,"ViewMode":"Prospects","DraftOrSentViewMode":"Draft","NewClubId":21}

Works fine in FF and Chrome.

Any ideas, why this is occurring and what I can try?

//The form setup

@using (Ajax.BeginForm("ProcessCompose", "NewClubOpeningTool", FormMethod.Post, new AjaxOptions { UpdateTargetId = "update_panel" }, new { @enctype = "multipart/form-data", id="ComposeForm" }))   

//The controller action that handles the form submit

       [HttpPost]
        public ActionResult ProcessCompose(NewClubInviteComposeEmailViewModel compose, IEnumerable<int> Recipients)
        {
            [...]

            return Json(new { Success = success }, "text/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
        }




 //This code lives in the view that has the AJAX form
 $(document).ready(function () {

        /***********************************************************
            Initialize the JQuery Form object
            This is how we are able to upload stuff via an AJAX form
        *************************************************************/

        var options = { 
            type:'post',
            data: $('#ComposeForm').serializeArray(),
            datatype: 'json',
            url: '/NewClubOpeningTool/ProcessCompose/',
            success: function (data) {
            if (data.Success) {
                alert('Success! We have data.Success!');
                $(".dialog").remove();
                $("#divInviteContentArea").load("/NewClubOpeningTool/InviteEmail?clubId=" + data.NewClubId + "&viewMode=" + data.ViewMode + "&draftOrSentViewMode=" + data.DraftOrSentViewMode);
            } else {
                alert('Error! We do not have data.Success!');
            }
        },
        error: function(jqXHR, textStatus) {
            alert('Error: ' + textStatus);
        }                   
    }; 
    $('#ComposeForm').ajaxForm(options);
        /*************************************************************
        Prevent the AJAX form from submitting twice
        **************************************************************/
        $("#ComposeForm").submit(function (e) {

             e.preventDefault();

             return false;


        });
    });
هل كانت مفيدة؟

المحلول

Everything is correct but you made a small mistake: ie:-

change datatype:'json' to dataType:'json' its T (caps) in ajax call.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top