Php Ajax显示导致已经创建的div
我有像主页一样的index.php,index.php中包含了sidebar.php。在index.php中,我有div id=content,其中一些内容已经加载。。在sidebar.php中,我有Php Ajax显示导致已经创建的div,php,jquery,ajax,Php,Jquery,Ajax,我有像主页一样的index.php,index.php中包含了sidebar.php。在index.php中,我有div id=content,其中一些内容已经加载。。在sidebar.php中,我有 <form id="search" method="post" action="" > <input type="search" name="search" id="search"> <input type="submit" name="se
<form id="search" method="post" action="" >
<input type="search" name="search" id="search">
<input type="submit" name="search" id="search" class="btnButton" value="Search"/>
</form>
那么,当我单击submit时,如何在div id=content中显示我的搜索结果呢?使用Jquery ajax从主页调用search.php。确保您引用jQuery库
//Main Page
<form id="search" method="post" action="" >
<input type="text" name="search" id="search">
<input type="submit" name="search1" id="search1" class="btnButton" value="Search"/>
</form>
<div id="content"></div>
<script>
$(document).ready(function(){
//jquery click event
$("#search").live("click", function(e){
//disable default form submit postpage
e.preventDefault();
//make ajax call to the search.php parsing the search textbox value as query string
$.get("search.php?s="+$("#search").val(), function(result){
//Result will be dumped in the div
$("#content").html(result);
});
});
});
</script>
//Search PHP Script search.php
<?php
//Get the search String
$string = $_GET["s"];
//DO search query and echo it on this page.
?>
您只需从jquery中选择元素,然后执行方法。ajax{} 比如说
$('#contentElementId').ajax({options...})
结果将加载到
<div id="contentElementId"></div>
id必须是唯一的这可能会让你感兴趣:搜索的可能重复与服务器端有关,html如何解决这个问题?请添加更多解释,这是一个AJAX任务…tnx Nwafor..这很好,很简单:很高兴听到这个消息。如果有用,请将其标记为有用。ID仍然是重复的。您应该使用如下的增量