我在'item_detail'(data.html)字段中输入了15个字符,但是我想在xml文件(item.xml)的'itemdetail'元素中只存储10个字符我该怎么做那?在xml文件中存储html表单值
data.html ----
Id:
Item Detail:
data.js -------
var xhr = createRequest();
function getData(dataSource, divID, id,itemd) {
if(xhr) {
var obj = document.getElementById(divID);
var requestbody ="idd="+encodeURIComponent(id)+"&itd="+encodeURIComponent(itemd);
xhr.open("POST", dataSource, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
obj.innerHTML = xhr.responseText;
} // end if
} // end anonymous call-back function
xhr.send(requestbody);
} // end if
} // end function getData()
data.php文件-----------
$id= $_POST["idd"];
$item_detail= $_POST["itd"];
$xml = new DomDocument();
$xml->load("item.xml");
$xml->formatOutput = true;
$items = $xml->firstChild;
$item = $xml->createElement('item');
$items->appendChild($item);
$id = $xml->createElement('id');
$itemdetail = $xml->createElement('itemdetail');
$item->appendChild($id);
$id->nodeValue = $id;
$item->appendChild($itemdetail);
$ItemDetail->nodeValue = $item_detail;
$xml->save("item.xml");
}
2011-04-24
ayman
+0
你想存储*首*十个字符,还是最后*十个?你想要保存比输入少五个字符吗?你能提供你想要实现的例子吗?顺便说一句,使用POST请求,你应该在用encodeURIComponent编码字符串后用''替换'%20'。 –
2011-04-24 12:25:05