I have a web page where I want to have an input box and a search button. It will search for movies matching input box. The search and parsing is done via php, but I want the results presented on the original page, as an updated div. I have the current html code:
<script type="text/javascript">
function goSearch(){
$("#Moviesearchdiv").load("MovieSearch.php");
}
</script>
<form action="JavaScript:goSearch()" method="POST">
<input type="text" name="moviename">
<input type="submit" name="submit" value="Search" >
</form>
<div id="Moviesearchdiv"></div>
My MovieSearch.php looks something like this:
<?php
$themovie = $_POST["moviename"];
$myurl = "http://my-url-here.com/search/?q={$themovie}";
$response = file_get_contents($myurl);
$result = json_decode($response, true);
$result=$result['movies'];
$totality = count($result);
for ($i = 0; $i <$totality; $i++) {
$mymovietitle = $result[$i]['original_title'];
$myposter = $result[$i]['poster_original'];
echo "<li><img src={$myposter} >{$mymovietitle}</li>";
}
?>
When I run it as is... nothing happens. If I manually change the first variable in MovieSearch.php to read something like:
$themovie = "Rocky";
This properly loads all the Rocky movies in my div as expected, without the page refreshing.
How can I properly pass the "moviename" input to the php?
Any help and advice is greatly appreciated.
Thanks,
Hernando