dpa0760 2012-12-18 00:45
浏览 54
已采纳

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);
  • 写回答

1条回答 默认 最新

  • douzhi9478 2012-12-18 00:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答