Click here to Skip to main content
16,020,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am calling webservice via my javascript. I have written validation when my resultset will be null, but when the select from my stored procedure will return no rows,it gets the data in my result variable as {"Table":[]} How do i validate this?
Here's my onSucess function:

C#
function onSuccessBindWidgetInvoice(result) {
    debugger;
    if (result != null) {
        if (pgrInvoices == null && pgrInvoices == undefined) {
            widgetId = 'widgetInvoices';        

            var loadedResult = Sys.Serialization.JavaScriptSerializer.deserialize(result);
            if (loadedResult.Table.length > 0) {
                widgetTitle = loadedResult.Table[0].ItemType;
                var getWidgetHtmlMarkup = getWidgetHtml(widgetId, widgetTitle);
                if ($get(widgetId) != null && $get(widgetId) != undefined) {
                    var htmlMarkup = getWidgetHtmlMarkup + createRows(loadedResult.Table.length, loadedResult.Table, widgetId);
                    var htmlMarkup = htmlMarkup + createPager(widgetId);
                    $get(widgetId).innerHTML = htmlMarkup;
                    pgrInvoices = $create(GEP.Scripts.Pager, { 'ImagePath': '../images/' }, null, null, $get('dvPager_' + widgetId));
                    pgrInvoices.set_WebServiceFn(bindWidgetInvoice);
                    pgrInvoices._ddlPageSize.value = 10;
                    pgrInvoices.set_StartIndex(1);
                    pgrInvoices.set_PageSize(5);
                    pgrInvoices.set_TotalCount(loadedResult.Table[0].TotalCount);
                }
                else
                    alert('Unable to attach ' + widgetId);
            }

        }
        else {
            widgetId = 'widgetInvoices';        
            var loadedResult = Sys.Serialization.JavaScriptSerializer.deserialize(result);
            if (loadedResult.Table.length > 0) {
                widgetTitle = loadedResult.Table[0].ItemType;
                if ($get(widgetId) != null && $get(widgetId) != undefined) {
                    var htmlRowMarkup = '';
                    htmlRowMarkup = createRows(loadedResult.Table.length, loadedResult.Table, widgetId);
                    $get('placedivAttContent_' + widgetId).innerHTML = htmlRowMarkup;
                    pgrInvoices.set_TotalCount(loadedResult.Table[0].TotalCount);
                }
                else
                    alert('Unable to attach ' + widgetId);
            }
        }
    }
    changeLoadingImgVisibility();
    $(document).ready(function () {
        //$('#widgetOrders').hide();
        $('#widgetInvoices').fadeIn(900);
    });
}
Posted
Updated 5-Jul-11 23:59pm
v2

1 solution

Hope this may help you out...
JavaScript
if (result != null && result.Table != null && result.Table.length > 0) { 
  // your existing code
} else {
  // error message or warning message...
}


Thanks & Regards,
Niral Soni
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900