简体   繁体   English

在 PHP 中使用 Jquery 变量

[英]Use a Jquery variable in PHP

I have a very long program, and I have this problem.我有一个很长的程序,我有这个问题。 I have the following code:我有以下代码:

<li>
    <label for="edit_cp">CP:</label>
    <input id="edit_cp" type="text" name="edit_cp" placeholder="Postal Code" required />

</li>

And In PHP:在 PHP 中:

$query = "SELECT    * FROM           shops";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<p style='font-size:12px'> <input type='radio' name='tienda' value='$row[ID]' required> $row[Nombre] ($row[Direccion])";
    }

mysql_close($link);

This is only a two parts of my program, so I can't use a form and get the $_POST or similar.这只是我程序的两个部分,所以我不能使用表单来获取 $_POST 或类似的。 I have to use the result of the edit_cp variable and use it into the php.我必须使用 edit_cp 变量的结果并将其用于 php.ini 文件。 I want it to calculate a nuber.我想让它计算一个 nuber。 For example if the entered number is for example 2 and in the while the number is 2, it will be selected.例如,如果输入的数字是例如 2,而数字是 2,则会被选中。

Try尝试

$.post( "path/to/handler", { edit_cp : $('#edit_cp').val()}).done(function( data ) {
    alert( "Data Loaded: " + data );
});

Don't forget to bind this script to some action, ex.:不要忘记将此脚本绑定到某些操作,例如:

$('#post').once('click',function(){
    $.post( "path/to/handler", { edit_cp : $('#edit_cp').val()}).done(
        function( data ) {alert( "Data Loaded: " + data );
        });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM