Solved

How do I grab html Pipe-delimited Ajax response?

Posted on 2007-11-20
1
868 Views
Last Modified: 2012-06-21
I have an ajax process that calls another page and that page returns an html page with just rows of pipe-delimited records on the page. How do I take that response from xmlHttp.response.Text and put into a multi-dimensional array, so each row is an element of the array. And the pipe separates each field of the row?
0
Comment
Question by:bemara57
1 Comment
 
LVL 7

Accepted Solution

by:
bdichiara earned 500 total points
ID: 20323596
////////    html    //////////

dog|cat|bird
red|blue|green
hot|cold|warm

////////    javascript    //////////

function convert(theHtml){
      var firstArray = theHtml.split("\n"); // this might need to change if using <br> instead of new lines.
      var finalArray = new Array();
      for(var i=0; i < firstArray.length; i++){
            finalArray[finalArray.length] = firstArray[i].split("|");
      }
      
      //you're all set. below just shows you it's in a 2-dimensional array
      for(var f=0; f < finalArray.length; f++){
            for(var c=0; c < finalArray[f].length; c++){
                  alert(finalArray[f][c]);
            }
      }
      
      return finalArray;
}
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

832 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