我正在尝试解决现有问题 - 我有两个文件。 php和b。 php和我使用HTTP传递一个值get to b。 PHP。里面b。 php我有以下JavaScript代码来获取HTTP获取值。通过使用以下代码,我可以获得值。然后,我试图用这个值调用一个js函数并相应地显示数据。但我没有得到任何数据,我认为这是为URL。
我怎样才能做到这一点?谢谢!
从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>
你可以通过使用php命令在你的javascript上从url获取数据。请参阅以下示例代码:
<script>
var search = '<?php echo $_GET['search'] ?>';
alert(search);
</script>