复习1【mvc】:mvc后端返回一定要加上JsonRequestBehavior.AllowGet

前端代码:

@{
    ViewBag.Title = "NullableTest";
    Layout = null;
}
<script src="~/Content/Scripts/jquery-2.1.1.js"></script>
<h2>NullableTest</h2>

<button id="btnGetValue">Get Value</button>
<script>
    $("#btnGetValue").click(function () {
        $.ajax({
            url: "GetBackEndValue", // 替换为实际接口地址
            method: "GET",
            dataType: "json",
            success: function (response) {
                console.log(response);
                // 判断后端返回的值是否为空
                if (isEmpty(response)) {
                    console.log("后端返回了空值");
                } else {
                    console.log("后端返回了有效数据:", response);
                }
            },
            error: function (xhr, status, error) {
                console.error("请求失败:", error);
            }
        });
    })
</script>

后端代码:

 通义千问上的解释:

 

posted @ 2025-04-14 10:34  katesharing  阅读(10)  评论(0)    收藏  举报