Solved

How do I grab html Pipe-delimited Ajax response?

Posted on 2007-11-20
1
870 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
[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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sort Multi-dimensional array 6 41
Make icons act like add/minus for qtys 6 37
How to open a new browser tab after executing php script 20 43
Error Handler 8 38
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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

738 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