简体   繁体   English

在表单提交或保持会话状态或xmlhttprequest之后,PHP curl无法刷新

[英]PHP curl do not refresh after form submit or keep in session, or xmlhttprequest

Sorry a newbie to PHP, I'm trying to do a curl form submit but want to keep the results after the first submit. 对不起,PHP的新手,我正在尝试进行curl表单提交,但希望在第一次提交后保留结果。 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. 它的值正确地传递到弹出窗口,但我不希望单击第二个提交时刷新屏幕。

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>

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

I've being trying to use httpRequest to do it async but there nothing being returned? 我正在尝试使用httpRequest使其异步,但是没有返回任何内容? API says return can be Text, HTML, or XML. API说return可以是Text,HTML或XML。 I've tried them all. 我已经尝试了所有。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM