asp.net 调用失败,出现404

rryofs0p  于 2023-05-19  发布在  .NET
关注(0)|答案(1)|浏览(131)

我正在尝试进行此 AJAX 调用:

function Test(){
            var results = new Array();

            var emp1 = { "ID": "12", "Name": "Manas" };
            results.push(emp1);

            var emp2 = { "ID": "2", "Name": "Tester" };
            results.push(emp2);

            var postData = { empList: results };

            $.ajax({
                url: 'Sprachen/SaveEmpList',
                data: JSON.stringify(postData),
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                beforeSend: function () {
                },
                success: function (result) {
                    alert(result);
                },
                complete: function () {
                },
                failure: function (jqXHR, textStatus, errorThrown) {
                    alert("Status: " + jqXHR.status + "; Error: " + jqXHR.responseText); // Display error message
                }
            });
        }

我的控制器:

public static bool SaveEmpList(List<Employee> empList)
        {
            try
            {
                // Implement your logic to save EmpList in Database  
            }
            catch (Exception ex)
            {
                // Log Error  
                return false;
            }

            return true;
        }

这是我单击按钮调用Test()函数之前的基本URL

https://localhost:44306/Jobs/Sprachen?categoryId=handwerk&handler=UserId

我得到了一个404。
我如何创建URL,这样我就不会得到404了?

eqqqjvef

eqqqjvef1#

这将起作用:

$.ajax({
                type: 'POST',
                url: "/Jobs/Sprachen/?handler=RandomNumber",
                data: JSON.stringify({ Min: testvariable, Max: "no" }),
                contentType: "application/json",
                dataType: "json",
            }).done(function (data) {
                console.log(data);
            })
            .fail(function (error) {
                //nothing for now
            });

相关问题