Chirag K
Chirag K

Reputation: 2434

Internal server error in ajax post request

enter image description here Guys I have problem with my ajax post request and it is not working for some dates i.e it does not hits controller but for some dates it works fine please help me to find out the bug Here is my code

$("#getInfo").click(function ()
{
    var elementValue = document.getElementById("tournamentID").value;
    var startDateValue = document.getElementById("filterDateStartnew").value;
    if (elementValue == null || elementValue == "" || startDateValue == null || startDateValue == "")
        {
            alert("please enter TournamentID and timestamp to get Info");
            return false;
        }
    $.ajax({
        type: "POST",
        cache: false,
        url: '/reports/gettournamentinfo',
        data: { tournamentID: elementValue,date: startDateValue },
        success: function (data)
        {
            var select = document.getElementById("TournamentLevel");
            var length = select.options.length;
            //Delete All Options
            $('#TournamentLevel')
                .find('option')
                .remove()
                .end()
            var opt = document.createElement("option");
            opt.text = "Any";
            opt.value = -1;
            document.getElementById("TournamentLevel").options.add(opt);
            var count = data[0];
            for (var i = 1; i <= count; i++)
            {
                var opt = document.createElement("option");
                opt.text = i;
                opt.value = i;
                document.getElementById("TournamentLevel").options.add(opt);
            }

            for (var index = 1; index < data.length; ++index)
            {
                var opt = document.createElement("option");
                opt.text = data[index];
                opt.value = data[index];
                document.getElementById("RunID").options.add(opt);
            }
            $("#SubmitForm").removeAttr('disabled');
        },
        error: function(data)
        {
            alert("there was no info for that tournamentID and that date");
            $.unblockUI();
            $('#TournamentLevel')
.find('option')
.remove()
.end()
            return false;
        }
    });

        return false;
});

Upvotes: 1

Views: 860

Answers (2)

Chintana Meegamarachchi
Chintana Meegamarachchi

Reputation: 1820

Check for the data formats. For example if the client using dd/mm/yyyy and the server is expecting mm/dd/yyyy, you will see a HTTP 500 error as the model binder will fail to do the binding

Upvotes: 1

RGS
RGS

Reputation: 5211

Change your ajax post method like below.

$.ajax({ url: "/reports/gettournamentinfo", contentType: "application/json; charset=utf-8", type: "POST",
                data: '{"tournamentID":"' + elementValue+ '", "date":"' + startDateValue + '"}',
                success: function (data) {      
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {  }
            });

Upvotes: 0

Related Questions