1

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;
});

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

but if there is a problem in dates how is it working for some dates?btw I tried before with dates and it was working just fine
if its a problem with formats, as long as you send dates like 1/1/2001, 12/12/2001, 6/5/2001 it will work. But the moment you send 13/2/2001 to a server which is expecting mm/dd/yyyy, the binder would fail and IIS will respond with a HTTP 500 error
Gotcha bro that's why when i am sending 14/03/2014 it sends me an error but when i am doing it with 12/03/2014 it does work
0

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) {  }
            });

Comments

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.