0

我在我的网页中嵌入了一个提交搜索的按钮。此表单的搜索值txtphp code. 我遇到的问题是php code它仅在网页加载时加载一次。这是一个问题,因为txt文件在不断变化,并且它的内容在第一次时才被读取。所以我想要的是在单击提交按钮时输入搜索值。换句话说,我正在寻找php code运行并填充搜索值 onClick。

这是表格:

<form id="search" action="http://www.example.com/search.php" method="get" target="_blank">
<input type="hidden" name="search" value="<?php $file = "http://www.clavederock.com.ar/zararadio/CurrentSong.txt";
   $f = fopen($file, "r");
   while ( $line = fgets($f, 1000) ) {
   $line = preg_replace("/-(.*?)-/", "", $line);
   print $line;}?>"/>  
<input type="hidden" name="language" value="es"/>
<input type="image" src="img/psue.png">
</form>

任何建议或帮助将不胜感激!!谢谢!

编辑:我看到 php 在页面交付之前被执行,因为它是服务器端脚本。为了解决这个问题,有没有办法让php code每 x 秒运行一次?就像你在 div 中所做的那样:

 setInterval(function(){
 $('#ID').load('example.php');
 }, 10000);
4

1 回答 1

4

您将不得不以不同的方式解决这个问题,PHP 是服务器端脚本(它在页面交付之前执行),而 JS 是客户端,这意味着它从页面交付到它的任何时间执行被陈列。

您可以尝试使用 AJAX,并查询文件并更改回调中的内容。

EDIT: I think I understand your question better. You are going to have to use AJAX, and have the PHP code in the file that gets actioned. You can post the input value as a get variable, i.e. ?input=value and then get that in your PHP file. Then use AJAX to get the response back, without reloading the page.

于 2012-12-18T00:51:35.153 回答