我试图改变使用AJAX我的PHP网页如下 内容index.php页面已输入申请的是调用函数按钮上点击执行,但我的问题是,页面重新加载是它使用ajax更新php页面使用post请求重新加载页面?
所以我想知道我在做什么错?
请注意,我现在用的是POST请求,以保持我的数据安全,因为w3schools.com推荐
inexd.php下面
Site TitleBalance Enquiry
Account Number
Search
function SendForm()
{
alert("Hello! SendForm start");
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("AccNum").innerHTML = xmlhttp.responseText;
}
};
alert("Hello! going to send ajax");
var x = xmlhttp.open("POST","AccData.php", true);
xmlhttp.send(document.getElementById("AccNum").value); // you want to pass the Value so u need the .value at the end!!!
alert(document.getElementById("AccNum").value);
alert("Hello! SendForm end");
}
下data.php文件代码文件代码
alert("Hello! php start processing");
$AccountNumber = $_POST['AccNum'];
$conn = oci_connect('admin', 'admin', 'localhost/JDT', 'AL32UTF8');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
alert("Hello! connected to oracle");
$sqlstr = 'SELECT CUSTOMER_ID,CUST_NAME,PHONE1 FROM customers where CUSTOMER_ID=:AccNum';
$stid = oci_parse($conn, $sqlstr); // creates the statement
oci_bind_by_name($stid, ':AccNum', $AccountNumber); // binds the parameter
oci_execute($stid); // executes the query
echo $AccountNumber;
/**
* THIS WHILE LOOP CREATES ALL OF YOUR HTML (its no good solution to echo data out like this)
*/
while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
echo "
";foreach ($row as $item) {
echo "
" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "";}
echo "
\n";}
echo "\n";
oci_free_statement($stid); // releases the statement
oci_close($conn); // closes the conneciton
?>
2016-08-13
samer