开发者

Search box to advanced URL

开发者 https://www.devze.com 2023-02-25 03:30 出处:网络
I have a search engine on my site and the URL for the SERPs are search/QUERY/1/. How c开发者_StackOverflow中文版an I make an HTML search box to fill in the QUERY section of my URL?

I have a search engine on my site and the URL for the SERPs are search/QUERY/1/.

How c开发者_StackOverflow中文版an I make an HTML search box to fill in the QUERY section of my URL?

It can't really use PHP but it could use javascript if it has to.


using jQuery:

Live Demo

$('#search_button').click(function() {
    var query = encodeURIComponent($('#search_query').val());
    var searchurl = 'http://www.mysite.com/search/{query}/1/';
    var newurl = searchurl.replace('{query}',query);
    alert(newurl);
    // $(location).attr('href',newurl);
});

<input type="text" id="search_query">
<input type="button" id="search_button" value="Search">


HTML :

<form action="index.php" method="post">
<input type="text" name="word" />
<button type="submit">Search</button>
</form>

index.php :

<?PHP
if( isset( $_POST['word'] ) )
{
    header( 'location: /search/' . $_POST['word'] . '/' );
    exit();
}
//Other index.php codes
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号