jQuery Ajax Callback for array result
<p>I have following <code>jQuery Ajax</code> scenario in which a  webmethod returns a collection of strings.</p>

<ol>
<li>The collection can be null</li>
<li>The collection can be non-null but zero records.</li>
<li>The collection has one or more records</li>
</ol>

<p>The following code works fine. It uses <a href="http://api.jquery.com/jQuery.isEmptyObject/" rel="nofollow">jQuery.isEmptyObject</a>. It is advised not to use <code>isEmptyObject()</code> when it is not a <code>Plain Object</code>.</p>

<p>How can we handle the result without using isEmptyObject() ?</p>

<p>Note: The ajax "result" is coming as "not plain".</p>

<p>Reference:</p>

<ol>
<li><a href="http://stackoverflow.com/questions/4994201/is-object-empty">is object empty?</a></li>
<li><a href="http://www.bennadel.com/blog/1919-Javascript-s-hasOwnProperty-Method-Is-More-Consistent-Than-The-IN-Operator.htm" rel="nofollow">Javascript's hasOwnProperty() Method Is More Consistent Than The IN Operator</a></li>
</ol>

<p><strong>CODE</strong></p>

<pre><code>//Callback Function
function displayResultForLog(result) 
{


if (result.hasOwnProperty("d")) 
{
    result = result.d
}


if ($.isPlainObject(result)) {
    alert('plain object');
}
else 
{
    alert('not plain');
}

if($.isEmptyObject(result))
{
    //Method returned null        
    $(requiredTable).append('No data found for the search criteria.');
}
else
{

    if (result.hasOwnProperty('length')) 
    {

        //Set the values in HTML
        for (i = 0; i &lt; result.length; i++) 
        {
            var sentDate = result[i];
        }
    }

    else 
    {
      //Method returned non-null object; but there is no rows in that        
      $(requiredTable).append('No data found for the search criteria.');
    }

  }

 }

function setReportTable(receivedContext) {

var searchInput = '111';
$.ajax(
        {
            type: "POST",
            url: "ReportList.aspx/GetReportsSentWithinDates",
            data: '{"searchInput": "' + searchInput + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            context: receivedContext, //CONTEXT
            success: displayResultForLog

        }
        );
 }
</code></pre>
