如何在选择框中的值发生变化时使用 AJAX、JSON 和 PHP 检索表单?
我有一个选择框,在选择其中的值时,我必须显示一个表单,其中有一个包含 javascript 日历功能的日期字段。我尝试使用普通的 AJAX 和 PHP 组合,但我没有在其中获取日历,所以我只需要知道如何使用 JSON 和 AJAX 和 PHP 实现它?
感谢
每一个帮助......
代码
这是我正在使用AJAX功能的Javascript:
<script>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(path,val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById('docfields').innerHTML="";
if(req.responseText != ''){
document.getElementById('docfields').innerHTML=req.responseText; //retuen value
}else{
document.getElementById('docfields').innerHTML="<br> \t<font size='2'><b>No Fields Available</b></font>";
}
}
}
};
req.open("GET", path+"getDocFields.php?doctype_id="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
</script>
下面是我需要用脚本标签中实例化的日历对象(tcal)来显示的HTML表单:
<form onsubmit="" action="" method="post" name="newdoc">
<table border="0" style="border: medium none;" id="docfield">
<tbody>
<tr>
<td style="border-right: medium none;">
Date
</td>
<td style="border-right: medium none;">
<input type="text" value="" maxlength="10" name="Test" style="width: 100px;" id="date">
<script>
new tcal ({
'formname': 'newdoc',
'controlname': 'Test'
});
</script>
</td>
</tr>
</tbody>
</table>
</form>
我没有显示日历...
I Have a select box, on selectinga value in it I have to display a form in which there is a Date field which include a javascript calendar functionalty. I tried it with normal AJAX and PHP combination, but I dont get the Calendar in it, So I just need to know How I can make it happen using JSON and AJAX and PHP?
Thanks
Every Help Is Appreciated....
THE CODE
This is The Javascript I am Using to AJAX function:
<script>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(path,val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById('docfields').innerHTML="";
if(req.responseText != ''){
document.getElementById('docfields').innerHTML=req.responseText; //retuen value
}else{
document.getElementById('docfields').innerHTML="<br> \t<font size='2'><b>No Fields Available</b></font>";
}
}
}
};
req.open("GET", path+"getDocFields.php?doctype_id="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
</script>
Below Is the HTML form which I need to display with Calendar object (tcal) instantiated in the script tag:
<form onsubmit="" action="" method="post" name="newdoc">
<table border="0" style="border: medium none;" id="docfield">
<tbody>
<tr>
<td style="border-right: medium none;">
Date
</td>
<td style="border-right: medium none;">
<input type="text" value="" maxlength="10" name="Test" style="width: 100px;" id="date">
<script>
new tcal ({
'formname': 'newdoc',
'controlname': 'Test'
});
</script>
</td>
</tr>
</tbody>
</table>
</form>
I am not getting the calendar displayed...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在响应 html 中看到 javascrip,如果 html 通过 ajax 调用,则永远不会执行该 javascrip。
尝试把那个javascript
after your XMLHttpRequest object fetches and puts data in '#docfields'.
希望它会有所帮助。
I see javascrip in the response html, which will never be executed if the html is coming through ajax call.
Try to put that javascript
after your XMLHttpRequest object fetches and puts data in '#docfields'.
Hope it will help.
伊姆兰是对的。您需要提取脚本代码并运行它。
这段代码可以很常用:
Imran is right. You need to extract the scriptcode and run it.
This code can be used very commonly: