复习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>
后端代码:

通义千问上的解释:

本文来自博客园,转载请注明原文链接:https://www.cnblogs.com/keeplearningandsharing/p/18824304
浙公网安备 33010602011771号