onClick输入php的值

onClick输入php的值

问题描述:

I have embeded a button in my web that submits a search. The search value of this form is inputed from a txt file by a php code. The problem I have is that this php code its loaded only once when the webpage loads. This is a problem because the txt file is constantly changing and its content gets read only that first time. So what I want is to make the search value to be inputed when the submit button gets clicked. In other words, I'm looking to make the php code to run and fill the search value onClick.

Here's the form:

<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>

Any suggestion or help will be aprecciated!! Thanks!

EDIT: I see php gets executed before the page is delivered because is server side scripting. To make a workaround this problem, is there a way to make the php code run every x seconds? Like you would make in a div:

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

我在我的网站中嵌入了一个提交搜索的按钮。 此表单的搜索值是通过 php code code>从 txt code>文件中输入的。 我遇到的问题是这个 php code code>在加载网页时只加载一次。 这是一个问题,因为 txt code>文件不断变化,其内容首次只读取。 所以我想要的是在点击提交按钮时使搜索值输入。 换句话说,我正在寻找 php code code>来运行并填充搜索值onClick。 p>

以下是表格: p>

 &lt; form id =“search”action =“http://www.example.com/search.php”method =“get”target =“_ blank”&gt; 
&lt;输入类型 =“hidden”name =“search”value =“&lt;?php $ file =”http://www.clavederock.com.ar/zararadio/CurrentSong.txt";
 $ f = fopen($ file,“  r“); 
 while($ line = fgets($ f,1000)){
 $ line = preg_replace(”/-(.*?)-/“,”“,$ line); 
 print $ 线;}&GT;?“/&GT;  
&lt; input type =“hidden”name =“language”value =“es”/&gt; 
&lt; input type =“image”src =“img / psue.png”&gt; 
&lt; / form&gt; 
   code>  pre> 
 
 

任何建议或帮助都会得到帮助!! 谢谢! p>

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

  setInterval(function(){
 $('#ID')。load('example.php'); 
}  ,10000); 
  code>  pre> 
  div>

You're going to have to tackle this a different way, PHP is server side scripting (it gets executed before the page is delivered) and JS is client side, which means it gets executed from when the page is delivered to any time when it is displayed.

You could try and use AJAX, and query the file and change the content in your callback.

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.