Sending data from Javascript/HTML to php to conduct search -


i'm trying implement simple search engine using php. should have .php continuously running on server , post json or somehow post server , have script run when posted? either way don't know how either. i've been reading cron jobs. apply here?

edit: users sees search box. types in query search box. presses enter. json query sent using ajax server. server uses json query sent search indices of documents, not search website. server returns results in json format. these results interpreted , displayed user.

i have search setup in php. i'm new php.

edit2: have search setup using elastic search. wanted know best practice in sending information javascript/html site php on server. apologize not being clear enough.

cron jobs wouldn't apply unless want schedule searches , notify users when search done (even though it's possible, it's not you're looking for).

ajax quite handy here if you'd add such functionality autocompletion. if you're expecting page reload, re-rendering whole page contents search results or redirecting page results, ajax isn't necessary, because you'd have 2 http requests rather one.

in opinion, need have single-input form search field posting via request.

so instance:

<form action="/search_results.php" method="get"> <input type="text" name="query" /> <button type="submit">search</button> </form> 

which redirect search results page url this: /search_results.php?query=some+simple+search

then, within php code can fetch query parameter using $_get['query'] can directly pass search engine (elastic search) analyse.

i haven't ever tried elastic search, if must pass json data, can encode query using:

$search = json_encode(array('query' => $_get['query'])); 

it's hard precise because haven't provided expected format search, think should on track.

feel free comment below if have questions :)


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -