我在php页面上有两个隐藏字段
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">
我不知道为什么会发生这种事?帮帮我。
1st函数调用ajax&设置响应如下
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("clinic").value=xmlhttp.responseText;
}
}
2nd函数调用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();
}
首先尝试type=text,type=hidden不会有问题。你为什么不能像这样使用
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("clinic").value=xmlhttp.responseText;
document.getElementById("flag").value=xmlhttp.responseText;
}
}
阅读有关.value与setAttribute可能是属性与特性的问题。我不知道你是如何或何时访问隐藏值的,但如果它是在表单提交之后,那么可能没有设置该属性,因为value设置了字段的当前值(属性(,而你会得到null。请尝试使用setAttribute。
根据所提供的信息,这是我的最佳猜测。