【发布时间】:2016-09-24 23:21:06
【问题描述】:
抱歉,PHP 新手,我正在尝试进行 curl 表单提交,但希望在第一次提交后保留结果。然后这些显示按钮,并根据单击哪个按钮,另一个提交在弹出窗口中显示第二个值。它正确地将值传递给弹出窗口,但我不希望在单击第二次提交时刷新屏幕。
欢迎指点
<?php session_start();
?>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<SCRIPT TYPE="text/javascript">
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=700,height=235,scrollbars=yes');
return false;
}
</SCRIPT>
<form action="index.php" method="post">
CHECK DOMAIN:
<input type="text" input name="checkDomain" value="<?php echo isset($_POST['checkDomain']) ? $_POST['checkDomain'] : '' ?>"/>
<button type="submit" value="Submit">Check</button>
<?php
$DomainArray = array("ie","com","net");
//IF WE WANT TO PARSE XML RESPONSE
function produce_XML_object_tree($raw_XML) {
libxml_use_internal_errors(true);
try {
$xmlTree = new SimpleXMLElement($raw_XML);
} catch (Exception $e) {
// Something went wrong.
$error_message = 'SimpleXMLElement threw an exception.';
foreach(libxml_get_errors() as $error_line) {
$error_message .= "\t" . $error_line->message;
}
trigger_error($error_message);
return false;
}
return $xmlTree;
}
if(!empty($_POST)) {}{
if(!empty($_POST["checkDomain"])) {
$checkDomain = $_POST["checkDomain"];
if(!empty($_POST["form2-submit"])) {
$whoIs = $_POST['form2-submit'];
}
if ($checkDomain !=null || $whoIs !=null)
{
//Check if a TLD has been entered
if (strpos($checkDomain, '.') !== FALSE)
{
$domain = substr($checkDomain, 0, strpos($checkDomain, "."));
$DomainList = substr($checkDomain, strpos($checkDomain, ".")+1);
$url = 'check1';
}
else if (!empty($_POST['form2-submit'])) {
$WhoisDomain = $DomainArray[$whoIs-1];
$url = 'check2';
}
else{
echo ' Checking all domains:';
$DomainList = implode(",",$DomainArray);
$url = 'check3';
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
$cont = produce_XML_object_tree($xml);
}
$_SESSION["otherXML"] =$xml;
foreach( $cont->Domain as $domain){
print '<br/>'.(string)$domain;
}
$index = 0;
foreach( $cont->RRPText as $rRPText ){
$index++;
print '<br/>'.(string)$rRPText;
//echo 'index'.$index;
if ($rRPText == "Domain not available")
{
print ' <button type="submit" name="form2-submit" onclick="popup(\'popup.php\')" value="'.$index.'">whois </button> ';
}
}
}
?>
</form>
</body>
</html>
【问题讨论】:
-
如果您不想在提交时出现“屏幕刷新”,您需要考虑制作Asynchronous Request
-
感谢我正在尝试执行异步 http 请求,但无法使其正常工作
标签: javascript php forms curl xmlhttprequest