AJAX & Web Api Post Method - How does it work?

后端 未结 7 656
臣服心动
臣服心动 2020-12-13 14:24

I am trying to write to my database using AJAX / Jquery and c#. Whenever I pass the parameter in to the C# code it shows as null. I am using the default template that visual

相关标签:
7条回答
  • 2020-12-13 15:31

    $("#updateuser").click(function () {

            var id = $("#id").val();
            var dataJSON = $("#username").val();
    
            alert("" + dataJSON);
    
            $.ajax({
    
    
                url: 'http://localhost:44700/api/Home/' + id,
                type: 'PUT',
                data: JSON.stringify(dataJSON),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
    
                success: function (data, textStatus, xhr) {
                    $.each(data, function (key, val) {
                        $("<li>" + val + "</li>").appendTo($("#names"));
                    })
                },
                error: function (xhr, textStatus, errorThrown) {
                    alert('Error in Operation');
                }
    
                })
    
        })
    
    0 讨论(0)
提交回复
热议问题