Plz help.. i want to limit it

i have this txt file name contacts.txt that contains this:

kate|female|kathryn bailey beckinsale|26-jul-1973|#23 underworld drive|(621) 142-7827|
jessica|female|jessica claire biel|03-mar-1982|27 texas avenue|(53)2344223|
johnny|male|john christopher depp ii|09-jun-1963|711 pirate road|(773) 476-6634|

my script is this:

function syncText() {
var xhr = new XMLHttpRequest();

  "get", "data/contacts.txt", false);


            if (xhr.status == 200) {
                var data = xhr.responseText;
                var items = data.split("|");

                var div = document.getElementById("header2");
                for (var i = 0; i < items.length; i++) {
                    var p = document.createElement("p");
                    var text = document.createTextNode(items[i]);
            } else {
                alert("data retrieval failed...");


<div id=“header2”>
<button onclick=“syncText()”>Pak</button>

i only want to retreive kat, jessica, johnny… please help me

Hi there RakiZtahX,

Welcome to the forums :slight_smile:

It would be better for you if your AJAX request was returning JSON, as opposed to a lump of text.
Maybe this is something for you to think about.

Anyway, as it is you need to do the following:[LIST]
[]Fetch the contents of the text file using AJAX and store the response in a variable called ‘data’
]The way to distinguish between “records” is that they are separated by a newline, therefore if you do: var items = data.split("\ ");, you then have an array of records.
[]Then, loop through the array of records and split each record at the pipe character: els = items[i].split("|");. This gives you a further array of the record’s “attributes”.
]Then select the first element in your new array, which is the name you are after, append it to a DocumentFragment
[*]Repeat this for all of your “records” and stick the fragment back into the DOM.
[/LIST]Here’s an example:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Format AJAX response text</title>
    <div id="header2">
      <button onclick="syncText()">Pak</button>
      <ul id="list"></ul>  
      function syncText() {
        var xhr = new XMLHttpRequest();"get", "contacts.txt", false);
        if (xhr.status == 200) {
          var data = xhr.responseText;
          var items = data.split("\
          var frag = document.createDocumentFragment();
          for (i=0; i<items.length; i++){
            els = items[i].split("|");
            li = document.createElement("li");
            li.innerHTML = els[0];
        } else {
          alert("data retrieval failed...");

I hope this helps you.

thank you…