我有一个 jquery ajax 帖子,当用户在消息框中输入并按 enter 时,这个 ajax 会触发。但是当用户写Nothing并按下回车时,这个ajax被触发并返回一些东西。但是我怎样才能从用户那里捕获空字符串?
cliKeyPressed : function(e) {
if(typeof e === "undefined" ) e = window.event;
if(e.keyCode == 13) {
var previousLine = "";
if($('#terminal').text()!== ""){
previousLine = $('#terminal').text();
previousLine = previousLine.replace("you entered: ", " ");
}
var inputData = $(e.currentTarget).val();
$('#terminal').text(previousLine + "\r\n" + inputData + "\r\n");
AjaxPost(inputData);
}
AjaxPost : function(data) {
$.ajax({
type : "POST",
url : "/api/user",
datatype : "application/json",
contentType: " text/plain",
data : dataAttribute,
success : function(data) {
},
error : function(error) {
},