<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function ltrim(str)
{
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1) {
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;
s = s.substring(j, i);
}
return s;
}
//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
var i = s.length - 1; // Get length of string
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;
s = s.substring(0, i+1);
}
return s;
}
// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
return rtrim(ltrim(str));
}
function test(data1,data2)
{
var req;
if (window.XMLHttpRequest) req=new XMLHttpRequest();
else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP");
else
{
alert("Browser not support");return false;
}
req.onreadystatechange=function()
{
if (req.readyState==4)
{
var result=req.responseText //รับค่ากลับมา
datas=result.split(',') //แยกกลับเป็น Array เหมือนเดิม
var d="" //แสดงผล ค่า Array ที่ได้รับกลับมา
for (n=0; n<datas.length; n++) {
d=d+" datas["+n+"] = "+datas[n]+"<br />"
document.getElementById("text1").value = trim(datas[0])
document.getElementById("text2").value = datas[1]
}
document.getElementById("show").innerHTML=d;
}
}
var str=Math.random();
var querystr="";
querystr+="test.php";
querystr+="?time="+str;
querystr+="&menu=test";
querystr+="&data1="+encodeURIComponent(data1);
querystr+="&data2="+encodeURIComponent(data2);
req.open("GET",querystr, true);
req.send(null);
}
</script>
</head>
<body>
<p><a href="#" onclick="test(1,2);">edit</a></p>
<input type="text" name="text1" id="text1" />
<input type="text" name="text2" id="text2" />
<div id="show"></div>
</body>
</html>