JQuery ajax call does not accept alphanumeric parameters!

JQuery seems to give an error when trying to pass an alphanumeric parameter as follows:

            $.ajax({
                type: "POST",
                url: "Default.aspx/AjaxTest",
                data: "{eventID:9a5}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    alert(msg.d);
                },
                error: function(e) {
                    alert("Event could not be added to calendar");
                }
            });

when the above method is called, the error callback is called. However, when I change the eventID parameter to a purely numeric value, it works fine and the success callback is called. I would like to pass the alphanumeric value to the server method, and this does not seem to work. Any help would be appreciated.

Ahmed

+3
source share
2 answers

, . , JSON: " JSON". , JSON , , . - , JSON , . :

        $.ajax({
            type: "POST",
            url: "Default.aspx/AjaxTest",
            data: "{eventID:'9a5'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                alert(msg.d);
            },
            error: function(e) {
                alert("Event could not be added to calendar");
            }
        });

.

+1

, Javascript?

$.ajax({
...
data: {"eventID": "9a5", "SomeNumericField": 25}
...
});

(: . , .)

+4

Source: https://habr.com/ru/post/1721013/


All Articles