i ssue in avoiding user from entering empty string in ajax post
I have a jquery ajax post and when a user wirte and press enter in a
textbox this ajax triggers and show the value of text box in a <pre> html
element. http://jsfiddle.net/LQg7W/2133/ obviuosly this jsfiddledoes not
show anything because I sis not put the ajax post inside it. but when the
user writes Nothing and press enter this ajax is triggered and return
something. but how can I catch the empty strings from user?
This is located in my view:
if(e.keyCode == 13) {
var currentLine = $('#terminal').text();
var inputData = $(e.currentTarget).val();
$('#terminal').text(currentLine + "\r\n" + inputData +
"\r\n"); //show the current and previous value
$("#textInput").val(" $> ");
AjaxPost(inputData);
}
and this ajax post is in model:
AjaxPost : function(dataAttribute, view, cacheId) {
console.log(cacheId);
var that = this;
if(dataAttribute === ""){
view.showMessage( " " , true);
}
$.ajax({
type : "POST",
url : "/api/user" ,
datatype : "application/json",
contentType: " text/plain",
data : dataAttribute,
success : function(data) {
console.log(data);
},
error : function(error) {
},
my problem is that my input data has default value of "$>" so I cannot
check this condition if (inputdata === "" ) because it is always full!!
Have any idea?
No comments:
Post a Comment