[英]Jquery ajax call from datepicker onSelect disappears textbox
I have a textbox with datepicker jquery plugin. 我有一个带datepicker jquery插件的文本框。 When i select a date ,post ajax call is made and i want to return some data from database and textbox should remain on top of the page so that furthur requests can also be made.
当我选择一个日期时,将进行post ajax调用,并且我想从数据库返回一些数据,并且文本框应保留在页面顶部,以便也可以进行进一步的请求。
<script>
$(document).ready(function(){
//create date pickers
$("#datepicker").datepicker(
{
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
onSelect: function(date)
{
$.ajax({
type:"POST",
url:"seestuffs.php",
data:date,
success: function(result)
{
document.write(result);
}
});
}
});
});
</script>
<body>
<p>Date: <input type="text" id="datepicker" name="date" /></p><br/>
</body>
And here is my seestuffs.php 这是我的seestuffs.php
<?php
if(isset($_POST['date']))
{
$date = $_POST['date'];
echo 'hello';
}
?>
But hello is not displayed on the page.Where am I going wrong!!Thanx in advance.. 但是你好并没有显示在页面上。我要去哪里错了!谢谢!
document.write will create a new document if called on a document that has already loaded. 如果在已加载的文档上调用document.write,则会创建一个新文档。 This is explained in this Question: JavaScript Document.Write Replaces All Body Content When Using AJAX .
在以下问题中对此进行了解释: 使用AJAX时,JavaScript Document.Write替换所有正文内容 。
So instead you need to add the result to the document either by appending a new node or using innerHTML eg: 因此,您需要通过添加新节点或使用innerHTML将结果添加到文档中,例如:
success: function(result) {
$('body').append('<p>'+result+'</p>');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.