Why are my values not being passed for ajax even when using trim and val? The problem arises from checking the values with trim and val, where they are validated based on whether something is typed or not. If nothing is entered, it sends false to validation; if there is input, it hides the validation message. Everything seems to be working fine except that the values do not get through, resulting in a new row without any values. What could be missing from my function to successfully pass the values? Here's the current code snippet:
var validation = "";
var values = {};
if ($.trim($("#name").val()) === "") {
$("#validateName").show();
validation = "false";
} else {
$("#validateName").hide();
}
if ($.trim($("#news").val()) === "") {
$("#validateNews").show();
validation = "false";
} else {
$("#validateNews").hide();
}
if(validation == "false"){
return false;
}
values['addnews'] = '';
$.ajax({
// Rest of the code //
This is how the values were previously passed. Here is the old code snippet:
$.each($('#add-news-form').serializeArray(), function(i, field) {
if((field.value == 0)){
validation = "false";
}
values[field.name] = field.value;
});
What could I add or modify in my ajax function to ensure the values are properly passed?