JQueryを使用して、PHPを使用して別のWebページにリダイレクトするWebページを作成しました。JQueryからPHPへのリダイレクションでフォームのコンテンツが送信されない
家:
私のコード私は ":未定義のインデックス:CでPOSTAL_CODE \ WAMP \ WWW \名前がMyWebSite \ target.phpを8行目にお知らせ" を得るため、残念ながら、フォームの内容が正しく送信されません。 HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form action="/" id="myform">
<input type="text" name="postal_code" placeholder="Search..." />
<input type="submit" value="Search" />
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<script>
$('#myform').submit(function() {
var url = 'target.php';
var postal_code = $('#postal_code').val();
$.post(url, { postal_code: postal_code },
function(data) {
$("#result").empty().append(data);
}
);
return false;
});
target.php
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=mydatabase', 'root', '', $pdo_options);
$response = $bdd->prepare('SELECT city FROM city_list where postal_code = ?');
$response->execute(array($_POST['postal_code']));
echo '<ul>';
while ($data = $response->fetch())
{
?>
<br/>The city you entered the postal code is : <?php echo $data['city'];
}
$response->closeCursor();
}
catch (Exception $e)
{
die('Error : ' . $e->getMessage());
}
?>
'$ _POST'変数に' print_r'または 'var_dump'を実行するとどうなりますか? – Nalum