4

私は検索エンジンに取り組んでいますが、メソッドに非常に深刻な問題がGETありPOSTます。

<input type="button" />ボタンを押すたびにページが更新されないようにするためにを使用しています。

ボタンを押すと、結果が表示されます (google_map、monumet picture、specs)。

今の問題は、このボタンを押して、フォームの値 + 結果 (google_map、monumet の写真、スペック) を送信して表示したいということです。

フォームの値を送信しないため、これは問題で<input type="button" />あり、私は本当に立ち往生しています。

4

2 に答える 2

3

確かに、ここにあなたのための実例があります:

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 ...";

応答では、応答とフォーム フィールドをすべて返します。

于 2013-09-15T15:30:56.053 に答える
1
onClick="document.getElementById('FormName').submit();"
于 2013-09-15T15:18:04.967 に答える