在ASP.NET Core Razor頁面中處理Ajax請求(轉)

  • 159
  • 0

在ASP.NET Core Razor頁面中處理Ajax請求(轉)

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
}
$('#FAB').change(function () {
        var id = $(this).find('option:selected').val;
        alert(id);
        $.ajax({
            type: "POST",
            url: '/RTTCSetting/SPECAlarmRTTCSetting?handler=FabOnchange',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("XSRF-TOKEN",
                    $('input:hidden[name="__RequestVerificationToken"]').val());
            },
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        }).done(function (data) {
            alert();
            console.log(data);
        })

    });

http://www.talkingdotnet.com/handle-ajax-requests-in-asp-net-core-razor-pages/