AJAX SENDING NULL DATA WHEN USING IE

ben reitman

Total Post:96

Points:676
Posted by  ben reitman
 1402  View(s)
Ratings:
Rate this:

When I use an AJAX request that sends data to controller with IE, it is sending null data. When I use Chrome or Firefox, my data from the key/value pairs are there in the controller's parameter variables.

Here is my javascript function:

$(".input-group.date").datepicker({

        autoclose: true

    }).on('changeDate', function (ev) {

        var schoolId = $(this).attr('data-schoolId');

        var date = new Date(ev.date).toUTCString();

        var schoolName = $(this).attr('data-schoolName');

        $.ajax({

            url: "@Url.Action("ChangeFulfillmentDate", "Admin")",

            type: "POST",

            data: {

                'newDate': date,

                'schoolId': schoolId

            },

            success: function (data) {

                if (!data.success) {

                    var n = noty({

                        text: 'Hold up! Something went wrong...<br />' + data.message,

                        layout: 'top',

                        type: 'error',

                        killer: true,

                        closeWith: ['button']

                    });

                }

                else {

                    var n = noty({

                        text: 'Fulfillment date for ' + schoolName + ' updated successfully',

                        layout: 'bottomRight',

                        type: 'success',

                        timeout: 3000,

                        killer: true,

                        closeWith: ['hover']

                    });

                }

            },

            error: function (xhr, status, error) {

                var n = noty({

                    text: 'Hold up! Something went wrong...<br />' + xhr.responseText,

                    layout: 'top',

                    type: 'error',

                    killer: true,

                    closeWith: ['button']

                });

            }

        });

    });

The ajax response error I get is:

The parameters dictionary contains a null entry for parameter 'newDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.JsonResult ChangeFulfillmentDate(System.DateTime, Int32)' in 'CurrReplenishment.Controllers.AdminController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.

Parameter name: parameters

Why is my AJAX call not sending the proper values for the key/value pairs? I have made sure that there is data in those javascript variables, as it works in Chrome and Firefox.

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: AJAX Sending Null data when using IE

    Hi Ben,

    It seems that ev.date is the problem, why don't you try something like this:

        $(".input-group.date").datepicker({

            autoclose: true,

            onSelect: function(selected) {

                var date = new Date(selected);

                /* Do something */

            }

        });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!