【发布时间】:2021-01-08 15:14:08
【问题描述】:
这是我的观点/模态是带有发送(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 点击功能 - 我下面的数据是空的。我也尝试了 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 + "'}",
dataType: "json",
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");
});
});
【问题讨论】:
-
你试过了吗 var r= $('#txtRecipient').val();警报(r);例如?
-
@Sergey 是的先生,我做了 [var x = $('#txtRecipient').val();] 但它是空的
-
我认为你的问题是自动完成。我不喜欢 url '/Send/AutoComplete/",请删除最后一个 "/" 并且没有检查成功的自动完成数据吗?它带来了你需要的东西吗?
-
@Sergey 是的先生,我确实删除了多余的“/”,是的,它带回了我需要的东西。
-
您是否从另一个网址中删除了多余的斜线?它现在是否有效?
标签: javascript jquery asp.net-mvc