1

別の検索方法を使用するeコマースエンジンスクリプトを使用しています。

このようなGETを使用するURLの代わりに:

http://search.com/searchc?q=the+query

それは使用しています

http://search.com/searchc/the+query

このフォームはURLを作成するため、POSTまたはGETするフォームを作成するにはどうすればよいですか。

http://search.com/searchc/?q=the+query


<form action="/searchc/" method="post">
    <input type="text" id="q" name="q">
    <input type="submit" value="go">
</form>

これも試してみました(getまたはpostはこれらの両方では機能しません)

<form action="/searchc/" method="post">
    <input type="text" id="" name="">
    <input type="submit" value="go">
</form>
4

3 に答える 3

1

信頼できる方法には 2 つのコンポーネントがあります。必要に応じてフォームの送信をリクエストに変換するクライアント側の JavaScript 操作と、(非 JS 状況のバックアップとして) フォームからリクエストを受け取り、それをリダイレクトする単純なサーバー側のリダイレクト ユーティリティです。変更されたとおり。

このようなもの(GETの場合):

<form action="http://www.example.com/redirect"
  onsubmit="location.href = document.getElementById('f1').value + 
  document.getElementById('q').value; return false">
<input type="text" id="q" name="f2">
<input type="submit" value="go">
<input type=hidden id=f1 name=f1 value="http://search.com/search/">
</form>

ここでhttp://www.example.com/redirectは、フォーム フィールドを読み取り、f1、f2、... という名前のフィールドを取得し、それらを単一の文字列に連結し、それを使用してリダイレクトするサーバー側のフォーム ハンドラーです。 URL。CGIスクリプトとして、これは

use CGI qw(:standard);
$dest = '';
$i = 1;
while(param('f'.$i)) {
   $dest .= param('f'.$i++); }
print "Location: $dest\n\n";
于 2012-07-23T13:48:20.797 に答える
1
<form action="/searchc/" method="post" onsubmit="this.action+=this.q.value;return true">
   <input type="text" id="q">
   <input type="submit" value="go">
</form>

スペースは %20 として送信されます

あなたが使用することができます

this.action+=this.q.value.split(' ').join('+')

それらを置き換える

于 2012-07-23T12:49:44.717 に答える
0

これは非常に奇妙な URL パターンですが、とにかく次のようなことができます。

$(function () {
    $('form').submit(function () {
        var url = '/searchc/' + encodeURIComponent($(this).find('[name=q]').val());
        window.location = url;
        return false;
    });    
});
于 2012-07-23T12:59:57.063 に答える