javascript - AJAX POST 不适用于 jQuery 1.9.0 或更高版本

标签 javascript jquery asp.net ajax

下面是我使用 AJAX 调用 ASPX 端静态 Web 方法的代码。它曾经与 jQuery 1.2.0 一起使用,但我需要更新我的 jQuery 2.1.1 ,现在 ajax 代码甚至不执行,因为代码永远不会落入“失败”部分

有人可以把我推向正确的方向吗?我有一种感觉,我可能会跳过新版本 jQuery 的引用?

            <%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../Design/jQueryCSS/bootstrap-select.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" src="../Design/scripts/jquery-2.1.1.js"></script>
    <script  type="text/javascript" src="../Design/scripts/bootstrap-select.js"></script>
    <script type="text/javascript" src="../Design/scripts/bootstrap.js"></script>
    <link href="../Design/jQueryCSS/bootstrap.css" rel="Stylesheet" type="text/css" />
    <script src="../Design/scripts/jquery.columnfilters.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Design/scripts/ToolBox.js"></script>


        <script type="text/javascript">
        $(document).ready(function () {
        var rtID = $('#<%=ddlRequestType.ClientID%>');
        //console.log(rtID[0].value);
        var temp = searchFields(rtID[0].value);
        console.log(temp);

        });

    function searchFields(rtID) {

        $.ajax({
            type: "POST",
            url: "Reports.aspx/Search",
            data: JSON.stringify({requestTypeID: rtID}),
            //data: 'requestTypeID: "' + rtID + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                /*if (response.d == true) {
                    console.log(response.data);
                }*/
                alert("hi");
            },
            failure: function (response) {
                console.log(response.data);
            }
        });
 </script>

错误:

enter image description here

是的,我确实验证了 requestTypeID 值:-)

最佳答案

尝试发送 JSON 对象而不是字符串:

$.ajax({
        type: "POST",
        url: "Reports.aspx/Search",
        data: {requestTypeID: rtID}, //Here
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            /*if (response.d == true) {
                console.log(response.data);
            }*/
            alert("hi");
        },
        failure: function (response) {
            console.log(response.data);
        }
    });

关于javascript - AJAX POST 不适用于 jQuery 1.9.0 或更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27491729/

相关文章:

javascript - 是否可以在HTML5.canvas中绘制大量简单的几何图形?

Javascript:IE event.preventDefault 为 null 或不是对象

javascript - 从父 ajax 调用问题引用的数据

jquery - 如何使用 jquery 自动完成组合框设置默认值?

javascript - 添加变量名称而不是其值,javascript

jquery - 如何从整个文档中删除一个类

c# - 隐藏动态div标签,包含动态输入按钮

asp.net - 分机未定义

asp.net - "The provided URI scheme ' https ' is invalid; expected ' http '. Parameter name: via"- 帮助?

asp.net - 我的 JSON 数组会是什么样子?