+ Reply to Thread
Results 1 to 3 of 3

Thread: Web service returning XML string

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Web service returning XML string

    I have a. ASP.Net web service that is being called by a JS function that I want to return XML formatted code which is then used to populate a dropdown list.

    I originally tried returning an object of type XMLWriter, but that didn't seem to work, so I just tried using a stringbuilder to create an xml structure to return to my JS complete function.

    The XML I am returning is
    Code:
    <catlist>
       <category>
          <ref>1</ref>
          <name>Item 1</name>
       </category>
    </catlist>
    
    In my JS function I am trying this, but am getting an error
    Code:
    function OnChangeComplete(result){
    var catlist = result.getElementsByTagName('category');
     if(catlist!=null){
       var subcat = document.getElementById('ctl00_ddlsubcategory');
       var opt = document.createElement('option');
       for(var i=0;i<subcat.length;i++){
          subcat.options[i].remove();
       }
       for(var x=0;x<catlist.childNodes.length;x++) {
          opt.value = catlist[x].childNodes[0].nodeValue;
          opt.text = catlist[x].childNodes[1].nodeValue;
          subcat.options.add(opt,null);
       }
     }
    }
    
    The error is result.getElementsByTagName is not a function.

    As far as I know this is a valid JS function to use on an XML document. See here.

    Is it because I am returning a string to the JS function? How can I go about returning correct XML that can be processed by JS?

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I seem to have fixed that issue by loading it as an xml document, but it's just adding blank options to the other dropdown.

    Any ideas?

  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. Seem to have sorted it.

    Needed to use:-
    Code:
    catlist[x].childNodes[0].childNodes[0].nodeValue
    

+ Reply to Thread

Similar Threads

  1. Returning XML document from Web Service
    By richyrich in forum .NET Development
    Replies: 8
    Last Post: April 17th, 2009, 09:24 AM
  2. Problem Returning a Book in a Library System
    By Xavier in forum Microsoft Access
    Replies: 19
    Last Post: April 6th, 2009, 03:27 PM
  3. Returning a table in sp executed in an sp...
    By Lauramc in forum SQL Development
    Replies: 1
    Last Post: August 6th, 2008, 10:05 PM
  4. Accessing a Public Property in a web service
    By richyrich in forum .NET Development
    Replies: 0
    Last Post: May 23rd, 2008, 09:42 AM
  5. windows service send emails every 10 days
    By peebman2000 in forum .NET Development
    Replies: 8
    Last Post: May 20th, 2008, 05:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO