微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从模态单击发送按钮时从视图文本框获取值

如何解决从模态单击发送按钮时从视图文本框获取值

这是我的观点/Modal 是带有 Send(btnSend) 按钮的,我没有运气 隐藏文本框和主视图中文本框的值。

                    <div class="form-group">
                        <input type="text" class="form-control" id="txtRecipient" placeholder="Enter Lastname" />
                        <input type="hidden" class="form-control" id="txtUserID" />
                    </div>

这是我的模态

留言 ×
                                </div>
                                <div class="modal-footer">
                                    <div class="row">
                                        <div class="col-md-8">
                                            <textarea class="form-control" rows="2" id="msgBox"></textarea>
                                        </div>
                                        <div class="col-md-4">
                                            <button type="button" class="btn btn-primary" id="btnSend">Send</button>
                                        </div>

                                    </div>

                                </div>
                            

这是我的 btSend Click 功能 - 我下面的 dets 是空的。我也尝试了 getElementById,但也没有用

$(function () {
                $("#btnSend").click(function () {
                 var x = $('#txtRecipient').val();
                  alert("btnSend" + x);

                    var dets = new Object();
                    dets.UserName = $('#txtRecipient').val();
                    dets.UserID = $('#txtUserID').val();
                    dets.MsgBox = $('#msgBox').val();
                    alert(dets);
                    $.ajax({
                        url: '/Send/SendMessage',data: JSON.stringify(dets),contentType: "application/json;charset=utf-8",dataType: "json",type: "Post",success: function (response) {
                            alert(response.MsgBox);

                        },error: function () {
                            //alert("something is wrong");
                        },complete: function () {
                           //alert("complete");
                        }



                    });
                });
            });

-我的函数数据库中的数据绑定到txtBoxes

$(function () {
                $("#txtRecipient").autocomplete({
                    source: function (request,response) {
                        $.ajax({

                            url: '/Send/AutoComplete',data: "{ 'username': '" + request.term + "'}",type: "POST",contentType: "application/json; charset=utf-8",success: function (data) {
                                response($.map(data,function (item) {
                                    return {
                                        label: item.UserName,value: item.UserID,//+ "," + item.UserName,};
                                }))
                            },error: function (response) {
                                alert(response.responseText);
                            },failure: function (response) {
                                alert(response.responseText);
                            }
                        });
                    },select: function (e,i) {
                        e.preventDefault();
                        $("#txtUserID").val(i.item.value);
                        $("#txtRecipient").val(i.item.label);


                        //alert(i.item.value);

                    },minLength: 1
                }).focus(function () {
                    //$(this).autocomplete("search");
                });
            });

解决方法

您的 ajax 网址无效:

url: '/Send/SendMessage/',//and
 url: '/Send/AutoComplete/',

你必须删除最后一个“/”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。