我没有得到任何输出 id_function.php 工作得很好,谁能帮帮我?
JavaScript
function get_details()
{
var oriz = document.getElementById("from").value;
var dizz = document.getElementById("to").value;
var id_orig_diz = $.ajax({
type: "POST",
url: 'id_function.php?orig='+oriz+'&des_id='+dizz,
dataType: "text",
async: false
}).responseText;
alert(id_orig_diz);
}
这是我的 PHP 但我没有得到任何 id
<?php
$name_1 = $_GET['orig'];
$name_2 = $_GET['des_id'];
try {
$dbuser = "kim";
$dbpass = "kim";
$conn = new PDO('mysql:host=localhost;dbname=destination', $dbuser, $dbpass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT pl_id FROM view_places WHERE name = :name LIMIT 1");
$stmt->bindParam(':name',$name_1);
$stmt->execute();
$result_1 = $stmt -> fetch();
$res1 = $result_1["pl_id"];
$stmt->bindParam(':name', $name_2);
$stmt->execute();
$result_2 = $stmt -> fetch();
$res2 = $result_2["pl_id"];
echo 'origin_number:'.$res1. ', '.'destination_id:'.$res2;
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>