Very basic error handling

develop
Sven Slootweg 12 years ago
parent 6ec1a2d90b
commit dd4c62bc4e

@ -36,14 +36,21 @@ else
array_unshift($db_query_arguments, '');
unset($db_query_arguments[0]);
$results_topics = Topic::CreateFromQuery("SELECT * FROM topics WHERE {$db_query}", $db_query_arguments);
try
{
$results_topics = Topic::CreateFromQuery("SELECT * FROM topics WHERE {$db_query}", $db_query_arguments);
$return_objects = array();
$return_objects = array();
foreach($results_topics as $topic)
{
$return_objects[] = $topic->AsDataset();
}
foreach($results_topics as $topic)
$sPageContents = json_encode($return_objects);
}
catch (NotFoundException $e)
{
$return_objects[] = $topic->AsDataset();
$sPageContents = json_encode(array("error" => "No results found for the specified query.", "query" => $query));
}
$sPageContents = json_encode($return_objects);
}

@ -136,3 +136,9 @@ a.title
{
content: ")";
}
.error
{
margin: 8px 16px;
font-size: 19px;
}

@ -11,7 +11,7 @@
/*$("input").val("data");
runSearch();*/
$("input").keypress(function(){
$("input").keyup(function(){
if(typeof search_timeout !== "null")
{
clearTimeout(search_timeout);
@ -27,38 +27,53 @@
$(".spinner").show();
var query = $("input#query").val();
$.post("/api/search", {q: query}, function(response){
$(".spinner").hide();
$(".results").html("");
if(query.length >= 3)
{
$.post("/api/search", {q: query}, function(response){
$(".spinner").hide();
$(".results").html("");
for(i in response)
{
if(response[i].items.length > 0)
if(typeof response.error == "undefined")
{
var result_wrapper = instantiateTemplate("result_wrapper");
var result_block = instantiateTemplate("result_topic");
result_block.children(".title").html(response[i].title);
result_block.children(".providername").html(response[i].provider);
result_block.appendTo(result_wrapper);
for(x in response[i].items)
for(i in response)
{
item = response[i].items[x];
var item_block = instantiateTemplate("result_item");
item_block.children(".title").html(item.title);
item_block.children(".title").attr("href", item.url);
item_block.children(".type").html(item.type);
item_block.insertAfter(result_block);
if(response[i].items.length > 0)
{
var result_wrapper = instantiateTemplate("result_wrapper");
var result_block = instantiateTemplate("result_topic");
result_block.children(".title").html(response[i].title);
result_block.children(".providername").html(response[i].provider);
result_block.appendTo(result_wrapper);
for(x in response[i].items)
{
item = response[i].items[x];
var item_block = instantiateTemplate("result_item");
item_block.children(".title").html(item.title);
item_block.children(".title").attr("href", item.url);
item_block.children(".type").html(item.type);
item_block.insertAfter(result_block);
}
result_wrapper.appendTo(".results");
}
}
result_wrapper.appendTo(".results");
}
}
else
{
$(".results").html("<div class='error'>No results.</div>");
}
setHandlers();
}, "json");
setHandlers();
}, "json");
}
else
{
$(".spinner").hide();
$(".results").html("<div class='error'>Enter at least 3 characters.</div>");
}
}
function setHandlers()

Loading…
Cancel
Save