【发布时间】:2014-08-01 09:51:00
【问题描述】:
我在 php 页面上有 2 个隐藏字段。
1.<input type="hidden" name="clinic" id="clinic">
2.<input type="hidden" name="flag" id="flag">
我想通过 ajax 响应设置这些字段的值。当我通过 ajax 响应设置这些值时,它没有反映。
但是当我从这些<input > 中删除type="hidden" 时,标签值是按要求设置的。
如下
1.<input name="clinic" id="clinic">
2.<input name="flag" id="flag">
我不知道为什么会这样?帮我。
第一个函数调用 ajax 并设置响应如下
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("clinic").value=xmlhttp.responseText;
}
}
第二个函数调用 ajax 并设置响应如下
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("flag").value=xmlhttp.responseText;
}
}
这是我实际的 ajax 请求
function showAppFlag(leadid,param)
{
serviceid = "1";
if (leadid=="")
{
document.getElementById("Flag").value="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('Flag').value= xmlhttp.responseText;
var flags = document.getElementById('Flag').value;
if(trim(flags)== "APP" && document.getElementById('cmb_subdispose').value == "APP")
{
alert('please select other disposition');
return;
}
else
{
showClinicFlag(leadid,param);
}
}
}
xmlhttp.open("GET","ctiservice.php?Type=FlagApps&lead_id="+leadid+"&service="+serviceid,true);
xmlhttp.send();
}
【问题讨论】:
-
Con 你发布代码是如何设置值的。
-
你能展示你的代码吗?
-
我想,我已经正确设置了值。请看编辑部分
-
警报(xmlhttp.responsetext)给出了什么?
-
它只返回预期值。唯一的问题是,该值没有设置为隐藏字段,我不知道为什么?
标签: php ajax input hidden-field