我有来自托管服务提供商的API脚本,并且使用此.php
脚本我只能检查域名是否可用。但是现在,如果我检查域名,页面将刷新,然后它将显示结果。
但是我希望结果能够在没有刷新的情况下显示出来。那可能吗?有人可以为我提供一个好的解决方案吗?
以下是结果部分:
<center> <font color="#FFF "> <?=$result?> </font> </center>`
这是整个.php
脚本:
<?php
require_once('Transip/DomainService.php');
if(isset($_GET['domain']) && strlen($_GET['domain']) > 0) {
$domain = $_GET['domain'];
try {
// Request the availability of a domain by using the Transip_DomainService API;
// we can get the following different statusses back with different meanings.
$availability = Transip_DomainService::checkAvailability($domain);
switch($availability) {
case Transip_DomainService::AVAILABILITY_INYOURACCOUNT:
$result = htmlspecialchars($domain)
. ' is helaas al <font color="red">bezet</font>, verhuizen is niet mogelijk ';
break;
case Transip_DomainService::AVAILABILITY_UNAVAILABLE:
$result = htmlspecialchars($domain)
. ' is ge-lockt, verhuizen is niet mogelijk!';
break;
case Transip_DomainService::AVAILABILITY_FREE:
$result = htmlspecialchars($domain)
. ' is <font color="green">beschikbaar!</font> <br><a href="http://xcoder.eu/coming/login.html" target="_blank">Klik hier</a> en registreer direct je domeinnaam! ';
break;
case Transip_DomainService::AVAILABILITY_NOTFREE:
$result = htmlspecialchars($domain)
. ' is helaas al <font color="red">bezet</font>, verhuizen is mogelijk ';
break;
}
}
catch(SoapFault $e) {
// It is possible that an error occurs when connecting to the TransIP Soap API,
// those errors will be thrown as a SoapFault exception.
$result = 'Oeps... Vul een geldige domeinnaam in. ';
}
}
else {
$domain = '';
$result = '';
}
?>
<head>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body style="background:transparent">
<form name="domainChecker" id="notifyMe" class="news-form" style="">
<div class="form-group">
<div class="form-inline">
<input type="text" style="text-align:center;" name="domain" value="<?=htmlspecialchars($domain)?>" required type="text" id="mail-sub" placeholder="Check of jouw domeinnaam beschikbaar is!" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Check of jouw domeinnaam beschikbaar is!'" class="form-control email srequiredField" required >
<button class="btn btn-lg submit" style="background:#ffc000;border:#eeb300;color:black" type="submit">Controleer</button>
</div>
</div>
<center><font color="#FFF "><?=$result?></font></center>
</form>
</body>
答案 0 :(得分:1)
是的,这是可能的。如果你愿意,可以使用jQuery ......
使用您的Main.php UI文件添加一些调用例如:getDomainAvail.php的jQuery。
所以
需要更多的例子吗?如果你愿意,我可以修改给你的代码。
干杯
答案 1 :(得分:1)
我确信@Chad Collins会有一些有用的东西,但我正在编写这个快速的脚本,所以我想即使你已经接受了他的答案,我也会发布它。你可以试试......或者不是(我没试过,所以如果它不起作用,我会删除我的答案):
<强>的index.php 强>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body style="background:transparent">
<form name="domainChecker" id="notifyMe" class="news-form" style="">
<div class="form-group">
<div class="form-inline">
<input type="text" style="text-align:center;" name="domain" value="" required type="text" id="mail-sub" placeholder="Check of jouw domeinnaam beschikbaar is!" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Check of jouw domeinnaam beschikbaar is!'" class="form-control email srequiredField" required >
<button class="btn btn-lg submit" style="background:#ffc000;border:#eeb300;color:black" type="submit">Controleer</button>
</div>
</div>
<center><font color="#FFF " id="resp"></font></center>
</form>
<script>
$("form").submit(function() {
$.ajax({
url: 'checkdomain.php',
data: $(this).serialize(),
type: 'post',
success: function(response) {
var DataResp = JSON.parse(response);
// Access the domain with-> DataResp.domain
// Access the result with-> DataResp.result
if(DataResp.result)
$("#resp").html(DataResp.result);
else
$("#resp").html("Empty message here.");
}
});
return false;
});
</script>
</body>
<强> checkdomain.php 强>
<?php
function CheckDomain($domain = false)
{
$domain = trim($domain);
if(empty($domain))
return array("domain"=>false,"result"=>false);
require_once('Transip/DomainService.php');
try {
// Request the availability of a domain by using the Transip_DomainService API;
// we can get the following different statusses back with different meanings.
$availability = Transip_DomainService::checkAvailability($domain);
switch($availability) {
case Transip_DomainService::AVAILABILITY_INYOURACCOUNT:
$result = htmlspecialchars($domain).' is helaas al <font color="red">bezet</font>, verhuizen is niet mogelijk ';
break;
case Transip_DomainService::AVAILABILITY_UNAVAILABLE:
$result = htmlspecialchars($domain).' is ge-lockt, verhuizen is niet mogelijk!';
break;
case Transip_DomainService::AVAILABILITY_FREE:
$result = htmlspecialchars($domain).' is <font color="green">beschikbaar!</font> <br><a href="http://xcoder.eu/coming/login.html" target="_blank">Klik hier</a> en registreer direct je domeinnaam! ';
break;
case Transip_DomainService::AVAILABILITY_NOTFREE:
$result = htmlspecialchars($domain).' is helaas al <font color="red">bezet</font>, verhuizen is mogelijk ';
break;
}
}
catch(SoapFault $e) {
// It is possible that an error occurs when connecting to the TransIP Soap API,
// those errors will be thrown as a SoapFault exception.
$result = 'Oeps... Vul een geldige domeinnaam in. ';
}
// Sorry, my original post didn't return anything here! Whoops!
$response['domain'] = (!empty($domain))? $domain: "";
$response['result'] = (!empty($result))? $result:"";
return $response;
}
echo json_encode(CheckDomain((isset($_POST['domain']))? $_POST['domain']:""));
?>