代码之家  ›  专栏  ›  技术社区  ›  user8518202

jquery级联数据未绑定其值

  •  -3
  • user8518202  · 技术社区  · 7 年前

    在这里我实现级联下拉列表在这里国家价值和;当我更改country时,它的名称具有约束力。它的值为comming,但值在url处不具有约束力。即时消息出错为 :44509/Api/Country/GetState/

     DDLCOUNTRY.change(function () {
                if ($(this).val() == "-1") {
                    DDLSTATE.empty();
                    DDLSTATE.append('<option/>', { value: -1, text: 'Select Country' })
    
                }
                else
                {
                    $.ajax({
                        url: 'http://localhost:44509/Api/Country/GetState/',
                        method: 'post',
                        dataType: 'json',
                        data: $(this).val() ,
                        success: function (data) {
                            debugger;
                            alert('success...');
                        }
                    })
                }
            })
        }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Jilani pasha    7 年前

    如果您的目的是发送值,那么您可以在url中传递参数,您可以这样做

    $.ajax({url:'http://localhost:44509/Api/Country/GetState/id=' + $(this).val(),
                            method: 'post',
                            dataType: 'json',
                            success: function (data) {
                                alert('success...');
                            }
                        });
    

    并确保“GetState”方法的类型为POST,并且正在接受名为“id”的参数。