I was trying to call the boolean from my Controller which is true, But when I call it now on my Javascript ajax I can't get it.
$.ajax({
url: "/Shop/Accessories",
contentType: "application/html; charset=utf-8",
type: 'GET',
dataType: "html",
success: (function (result) {
if (result) { //If I do result == true : still not working
$('#owl1').html(result)
$('#owl1').owlCarousel({
loop: true,
nav: false,
dots: false,
autoplay: false,
margin: 10,
responsive: {
0: {
items: 2
},
600: {
items: 3
},
1000: {
items: 4
}
}
})
} else {
$(".noItem1").html(result);
}
}),
error: (function (xhr, status) {
alert(status);
})
})
I am using a dataType: html for the return View when the database doesn't have any data
using (SqlConnection con = new SqlConnection(constring))
{
string command = "select item_image, item_name, item_price item_number, item_type, date_added from cooking_items";
con.Open();
using (SqlCommand cmd = new SqlCommand(command, con))
{
cmd.CommandTimeout = 60;
SqlDataReader Creader1;
Creader1 = cmd.ExecuteReader();
if (Creader1.HasRows == true)
{
con.Close();
con.Open();
DataTable dt = new DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
con.Close();
return View("Cooking", dt);
}
else
{
return View("Cooking"); //When there's no data, these is the one who should call my ajax.
}
}
}