html中输入存储为xml,在xml文件中存储html表单值

我在'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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值