dousi8931 2012-09-13 20:57
浏览 66
已采纳

将表单字段值传递给PHP文件

I'd like to do a dynamic search function using jQuery and PHP. I'm struggling passing the HTML form field to the JQUERY function (which would then get passed to the PHP file).

My major questions are:

1) How do I pass form "Input" field into Jquery function?

2) How do I get the PHP result in the form "Output" field?

I currently have... (simplified)

JQUERY:
$.get("SEARCH.php", {"_input" :  $('input[name=input]').val()},
function(returned_data) 
{
   $("input[name=output]").val(returned_data);
}


SEARCH.php:
$input = 'Welcome ' . $_GET['_input'];
echo $input;
//should be "Welcome" plus whatever I type in to "input"



HTML FORM:
input: <input type="text" name="input" value="" /> 
output: <input type="text" name="output" id="output" />         

Thank you!

  • 写回答

2条回答 默认 最新

  • douchi1945 2012-09-13 21:01
    关注

    jQuery

    $.get("SEARCH.php", {"_input" : $('input[name=input]').val() },
    function(returned_data) {
       $("input[name=output]").val( returned_data );
    }
    

    HTML

    input: <input type="text" name="input" value="" />
    output: <input type="text" name="output" />
    

    PHP Use echo instead of return since it looks that your code isn't in function:

    $input = $_GET['_input'];
    do some parsing of the input
    echo $result;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料