简体   繁体   中英

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:

$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. I have to use the result of the edit_cp variable and use it into the php. I want it to calculate a nuber. For example if the entered number is for example 2 and in the while the number is 2, it will be selected.

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 );
        });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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