你真的不 「需要」 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) –