我正在研究一个搜索引擎,我遇到了一个非常严重的问题 GET
和 POST
方法。
我正在使用 <input type="button" />
以避免每次按下按钮时页面都刷新。
按下按钮后,我会显示一个结果(google_map、monumet 图片、规范)。
现在的问题是我想通过按此按钮提交并显示表单值 + 结果(google_map、monumet 图片、规范)。
这是一个问题,因为 <input type="button" />
不提交表单值,我真的被卡住了。
最佳答案
当然,这是一个适合您的示例:
index.php
<!DOCTYPE html>
<html>
<head>
<title>Working Example</title>
</head>
<body>
<form id="search-form">
<input type="text" name="text1" id="text1" value=""><br>
<input type="text" name="text2" id="text2" value=""><br>
<input type="text" name="text3" id="text3" value=""><br>
<input type="button" id="search-button" name="search-button" value="search">
</form>
<div id="response"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#search-button').click(function(){
$.ajax( {
type: "GET",
url: 'response.php',
data: $('#search-form').serialize(),
success: function(response) {
$('#response').html(response);
}
} );
});
});
</script>
</body>
</html>
response.php
<?php
echo "text1: " . $_GET['text1'] . "<br>";
echo "text2: " . $_GET['text2'] . "<br>";
echo "text3: " . $_GET['text3'] . "<br>";
echo "your response ...";
在响应中,您返回任何响应,加上表单字段。
关于php - 我可以使用 <input type ="button"/> 提交表单值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18813928/