表单提交或保持会话或xmlhttprequest后,PHP curl不会刷新

时间:2022-09-25 15:00:27

Sorry a newbie to PHP, I'm trying to do a curl form submit but want to keep the results after the first submit. These then display buttons and depending which button is clicked another submit displays the second values in a popup. Its passing the values to the popup correctly but I dont want the screen to be refreshed when the second submit is clicked.

对不起PHP的新手,我正在尝试做一个卷曲表单提交,但想在第一次提交后保留结果。这些然后显示按钮并根据单击哪个按钮,另一个提交在弹出窗口中显示第二个值。它正确地将值传递给弹出窗口但我不希望在单击第二个提交时刷新屏幕。

Any pointers be appreciated

任何指针都值得赞赏

<?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>

2 个解决方案

#1


0  

If you don't want the page to be refreshed you should make an AJAX call.

如果您不希望刷新页面,则应进行AJAX调用。

To make life easier you could use jQuery's POST .

为了让生活更轻松,你可以使用jQuery的POST。

#2


0  

I've being trying to use httpRequest to do it async but there nothing being returned? API says return can be Text, HTML, or XML. I've tried them all.

我正在尝试使用httpRequest来执行异步但没有返回任何内容? API表示返回可以是Text,HTML或XML。我已经尝试过了所有这些。

<SCRIPT TYPE="text/javascript">

function httpGetAsync()
  {
   var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", "URL....", true);
        xmlHttp.send( null );
alert(xmlHttp);
 alert(xmlHttp.responseText);
    return xmlHttp.responseText;
}
  </SCRIPT>

#1


0  

If you don't want the page to be refreshed you should make an AJAX call.

如果您不希望刷新页面,则应进行AJAX调用。

To make life easier you could use jQuery's POST .

为了让生活更轻松,你可以使用jQuery的POST。

#2


0  

I've being trying to use httpRequest to do it async but there nothing being returned? API says return can be Text, HTML, or XML. I've tried them all.

我正在尝试使用httpRequest来执行异步但没有返回任何内容? API表示返回可以是Text,HTML或XML。我已经尝试过了所有这些。

<SCRIPT TYPE="text/javascript">

function httpGetAsync()
  {
   var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("GET", "URL....", true);
        xmlHttp.send( null );
alert(xmlHttp);
 alert(xmlHttp.responseText);
    return xmlHttp.responseText;
}
  </SCRIPT>