【问题标题】:value from JS file to JSON but the value appears to be null从 JS 文件到 JSON 的值,但该值似乎为空
【发布时间】:2018-04-22 14:01:35
【问题描述】:

亲爱的,

我目前正在尝试将 JS 文件中的值发送到 JSON,但 selectedTxt 的值似乎为空。

$('.Dropdown1 .Dropdown2').change(function () {



        $.postJSON('/files/html.aspx', {
            action: 'myAction', id: $(this).val(), chosenTxt: $('.Dropdown1 .Dropdown2 option:selected').text()
        }, function (j) {

            $('.html .content').html(j.html);

        });

    });

即使我在发送值之前尝试了警报并且似乎存在一个值,但是在我的 json 中当我调用它时它只是 NULL

【问题讨论】:

    标签: javascript .net json


    【解决方案1】:

    看起来你正在尝试加入两个下拉列表的文本,我不认为.text 可以这样工作,试试这个:

    chosenTxt: $('.Dropdown1 option:selected').text() + ' ' + $('.Dropdown2 option:selected').text()
    

    【讨论】:

    • 但是当我在 alert 中打印出我想要的值
    猜你喜欢
    • 2016-09-24
    • 2011-01-27
    • 1970-01-01
    • 2020-04-20
    • 2019-04-18
    • 1970-01-01
    • 2020-12-30
    • 2023-04-09
    • 2021-03-30
    相关资源
    最近更新 更多