Link to home
Start Free TrialLog in
Avatar of jonatec
jonatecFlag for United Kingdom of Great Britain and Northern Ireland

asked on

jQuery how to get returned .ajax() element count ?

My attached code calls a Web Service. I am trying to determine if it returns any elements, if none found I can put out a suitable message.

Please check my code, the .size() keeps returning 0, where am I going wrong with this?

[ thanks ]
function fnGetDictDefinition() {

    $.ajaxSetup({ cache: false });

    $.ajax({
      type: "GET",
      url: "http://services.aonaware.com/DictService/DictService.asmx/Define",
      data: "word=" + $("#txtWord").val(),
      dataType: "xml",
      success: function(xml) {
        var name = "";
        var word_def = "";
        var buf = "";
        
        var found = $("xml").find("Definition");
        alert(found.size())

        
        $(xml).find("Definition").each(function() {
          name = $("Name", this).text();
          buf += "<b>Dictionary:</b>&nbsp;" + "<label>" + name + "</label>" + "<br />";
          word_def = $("WordDefinition", this).text();
          buf += "<b>Definition:</b>&nbsp;" + word_def + "<br />";
          buf += name + "<hr />";
        });
        $("#sec01").html(buf);
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(ajaxOptions);
        alert(thrownError);
      }
    });

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonatec

ASKER

Excellent thanks !!
You're welcome! Thanks for the points!