Update templates/index.html
Browse files- templates/index.html +33 -20
templates/index.html
CHANGED
|
@@ -417,26 +417,39 @@
|
|
| 417 |
type: 'POST',
|
| 418 |
data: $(this).serialize(),
|
| 419 |
success: function (response) {
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
error: function () {
|
| 441 |
alert('Could not connect to server.');
|
| 442 |
btn.html(oldText);
|
|
|
|
| 417 |
type: 'POST',
|
| 418 |
data: $(this).serialize(),
|
| 419 |
success: function (response) {
|
| 420 |
+
if (response.predicted_crop_list) {
|
| 421 |
+
// 1. LOGIC: Check if "All" is present in the list (case-insensitive)
|
| 422 |
+
const containsAll = response.predicted_crop_list.some(crop =>
|
| 423 |
+
crop.trim().toLowerCase() === 'all'
|
| 424 |
+
);
|
| 425 |
+
|
| 426 |
+
// 2. If "All" is found, hide the box and stop.
|
| 427 |
+
if (containsAll) {
|
| 428 |
+
$('#result-box').hide();
|
| 429 |
+
console.log("Recommendation contained 'All' - Omitted results.");
|
| 430 |
+
}
|
| 431 |
+
// 3. Otherwise, proceed to show the results normally
|
| 432 |
+
else {
|
| 433 |
+
$('#result-box').fadeIn();
|
| 434 |
+
var resultsDiv = $('#crop-results');
|
| 435 |
+
resultsDiv.empty();
|
| 436 |
+
|
| 437 |
+
response.predicted_crop_list.forEach(function (crop) {
|
| 438 |
+
resultsDiv.append('<div class="crop-tag">' + crop + '</div>');
|
| 439 |
+
});
|
| 440 |
+
|
| 441 |
+
// Scroll down to results
|
| 442 |
+
$('html, body').animate({
|
| 443 |
+
scrollTop: $('#result-box').offset().top - 50
|
| 444 |
+
}, 800);
|
| 445 |
+
}
|
| 446 |
+
} else if (response.error) {
|
| 447 |
+
alert('Prediction Error: ' + response.error);
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
btn.html(oldText);
|
| 451 |
+
btn.prop('disabled', false);
|
| 452 |
+
},
|
| 453 |
error: function () {
|
| 454 |
alert('Could not connect to server.');
|
| 455 |
btn.html(oldText);
|