使用jquery从textbox获取值[通过php变量输出]

时间:2012-02-19 06:43:54

标签: php jquery

main.php:

<SCRIPT type="text/javascript">     

    $("#btnSubmit").click(function () {                 
        alert("What will i put here!");
    });

</SCRIPT>      

<input type = "submit" id = "btnSubmit" value = "Try IT!" />

<div id = "show_search2">
</div>

output.php:

<?php $val = $_POST['btnSubmit'];
echo "<H1>$val</H1>"; ?>

哪些特定的jQuery功能可以获得btnSubmit的价值并通过$_POST访问它并将其输出到div show_search2?我使用了prototype.js,但它与索引中的其他JS脚本冲突。

注意:我的所有脚本源都包含在索引中,这就是我在这篇文章中没有包含源代码的原因。

1 个答案:

答案 0 :(得分:1)

你的意思是这样的:


$("#btnSubmit").click(function (e) {
    e.preventDefault();
    var submitVal = $(this).val();
    $.ajax({
       type: "POST",
       url: "url_of_your_output.php",
       data: {btnSubmit : submitVal},
       success: function(response) {
            $("#show_search2").html(response);  //response from output.php
       }
    });
});