我被困在这个问题上。我一直在尝试使用http()
,但似乎什么也没做。
这是表单(它ajax_request
在我提交时调用,这很好用):
<form name='form-main'>
<input id='host' type='text' placeholder='Host' />
<input id='user' type='text' placeholder='Username' />
<input id='db' type='text' placeholder='Database' />
<input id='pass' type='password' placeholder='Password' />
</form>
这是ajax_request
一部分:
function ajax_request() {
var host = document.getElementById('host').value;
var user = document.getElementyById('user').value;
var db = document.getElementById('db').value;
var pass = document.getElementById('pass').value;
var submitTo = 'DB.php';
//alert(submitTo);
http('POST', submitTo, ajax_response, 'Host='+host);
}
这是ajax_response
:
function ajax_response(data) {
document.getElementById('web').value = data;
}
DB.php
最后,这是我试图调用的 PHP :
<?php
$Host = $_POST['Host'];
$User = $_POST['User'];
$DB = $_POST['DB'];
$Pass = $_POST['Pass'];
$iDB = new mysqli($Host, $User, $DB, $Pass);
if($iDB->connect_errno) echo "no";
else echo "yes";
?>
我在这里想要实现的是从 PHP 中获取“是”或“否”的响应并将其输出ajax_response