你真的不 “需要” AJAX这个,因为你可以把它提交给自身和包括进程文件:
的index.php
<div id="result">
<?php include('process.php'); ?>
</div>
<form action="index.php" id="form" method="get">
<input type="text" id="q" name="q" maxlength="16">
<input type="submit" name="submit" value="Submit">
</form>
process.php
<?php
// Check if form was submitted
if(isset($_GET['submit'])){
$result = $_GET['q'];
if($result == "Pancakes") {
echo 'Result is Pancakes';
}
else {
echo 'Result is something else';
}
}
?>
实现AJAX将使事情更加用户友好,但它绝对使您的代码复杂化。所以祝你好运!
这是一个jQuery的Ajax例子,
<script>
//wait for page load to initialize script
$(document).ready(function(){
//listen for form submission
$('form').on('submit', function(e){
//prevent form from submitting and leaving page
e.preventDefault();
// AJAX goodness!
$.ajax({
type: "GET", //type of submit
cache: false, //important or else you might get wrong data returned to you
url: "process.php", //destination
datatype: "html", //expected data format from process.php
data: $('form').serialize(), //target your form's data and serialize for a POST
success: function(data) { // data is the var which holds the output of your process.php
// locate the div with #result and fill it with returned data from process.php
$('#result').html(data);
}
});
});
});
</script>
如果你对AJAX(这是它的方式)非常肯定,那么读一下它。谷歌'AJAX'至少:) – Alvaro
你已经尝试过的AJAX?尝试使用AJAX,并告诉我们这个问题。 –
[** Google展示div格式php **](https://www.google.ca/search?q=show+result+in+div+form+php&ie=utf-8&oe=utf-8&rls=org .mozilla:en-US:official&client = firefox -a&channel = np&source = hp&gws_rd = cr) –