[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-08-18
3
Medium Priority
?
387 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:jonatec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33464254
Remove the double quotes
$("xml").find("Definition");
$(xml).find("Definition");
0
 

Author Closing Comment

by:jonatec
ID: 33464329
Excellent thanks !!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33464341
You're welcome! Thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question