Reputation: 73
I am trying to solve an existing problem - I have two files a. php and b. php and I am passing one value using HTTP get to b. php. Inside b. php I have following JavaScript code to get the HTTP get value. And by using the following code I am able to get the value. Then, I am trying to call a js function with this value and show data accordingly. But I am not getting any data, I assume it's for the URL.
How can I achieve that? Thanks!
post data from a.php (search=test) b.php?search=test
$(document).ready(function() {
var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
var query = document.location
.toString()
.replace(/^.*?\?/, '')
.replace(/#.*$/, '')
.split('&');
for(var i=0, l=query.length; i<l; i++) {
var aux = decodeURIComponent(query[i]).split('=');
$_GET[aux[0]] = aux[1];
}
callA("category",$_GET['search']);
}
});
<?php echo '<form action="../b?search=<?php $search_all ?>" method="get" style="display:inline;">';?>
<input type="text" name="search" id="search" value="Search by film, director or keyword" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search by film, director or keyword') {this.value = '';}" />
<input type="submit" />
</form>
Upvotes: 0
Views: 59
Reputation: 872
You can get the data from url on your javascript by just using the php command in it. see sample code below:
<script>
var search = '<?php echo $_GET['search'] ?>';
alert(search);
</script>
Upvotes: 1