Please help me...
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|kate@lycans.net
jessica|female|jessica claire biel|03-mar-1982|27 texas avenue|(53)2344223|jbiel@yahoo.com
johnny|male|john christopher depp ii|09-jun-1963|711 pirate road|(773) 476-6634|jsparrow@piratebay.org
my script is this:
function syncText() {
var xhr = new XMLHttpRequest();
xhr.open("get", "data/contacts.txt", false);
xhr.send(null);
if (xhr.status == 200) {
var data = xhr.responseText;
var items = data.split("|");
items.sort();
var div = document.getElementById("header2");
for (var i = 0; i < items.length; i++) {
var p = document.createElement("p");
var text = document.createTextNode(items[i]);
p.appendChild(text);
div.appendChild(p);
}
} else {
alert("data retrieval failed...");
}
}
html
<div id="header2">
<button onclick="syncText()">Pak</button>
</div>
If you need help (despite the useless thread heading)
if would be nice if you could state what the problem is.
You should also surround you script with [ code] and [ /code] tags (without the spaces)
to make it easier to read your problem.
im sorry.. the problem is.. i want only to get the kate jessica and johnny... without editing the txt file.
Still not very clear as to final results, so this is just a guess...
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Untitled </title>
<script type="text/javascript">
var textInput = [
'kate|female|kathryn bailey beckinsale|26-jul-1973|#23 underworld drive|(621) 142-7827|kate@lycans.net',
'jessica|female|jessica claire biel|03-mar-1982|27 texas avenue|(53)2344223|jbiel@yahoo.com',
'johnny|male|john christopher depp ii|09-jun-1963|711 pirate road|(773) 476-6634|jsparrow@piratebay.org'
];
</script>
<style type="text/css">
#debugger { font-size:3em; }
</style>
</head>
<body>
<div id="debugger"></div>
<script type="text/javascript">
var txtArr = [];
var tmpArr = [];
for (var i=0; i<textInput.length; i++) {
txtArr = textInput[i].split('|');
tmpArr.push(txtArr[0]);
}
document.getElementById('debugger').innerHTML = tmpArr.join('<br>');
</script>
</body>
</html>
this is contacts.txt placed in a notepad and im accessing it externally...
contacts.xt contains this information
kate|female|kathryn bailey beckinsale|26-jul-1973|#23 underworld drive|(621) 142-7827|kate@lycans.net
jessica|female|jessica claire biel|03-mar-1982|27 texas avenue|(53)2344223|jbiel@yahoo.com
johnny|male|john christopher depp ii|09-jun-1963|711 pirate road|(773) 476-6634|jsparrow@piratebay.org
i want to extract the value of kate, jessica, johnny and place it in a div
Your ajax call will work best when then .txt file is on the server.
I believe only IE can read the file locally, and that might be using some special code to replace the ajax call.
Modify my last post to pull in the .txt file using ajax logic from the server.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks