2017-01-07 3 views
0

Я пытаюсь мою руку на AJAX, который я не самый большой в, мой код страницы:AJAX форма не вызывает POST

<?php 
include('includes/db_connection.php'); 
include('includes/sessions.php'); 
include('includes/functions.php'); 
include('includes/header.php'); 
include('includes/navbar-logged.php'); 
require_once('api-sape.php'); 
// init sape 
$sape  = new SapeApi(); 
$userId  = $sape->login(SAPE_USER, SAPE_PASS); 

?> 
    <style type="text/css"> 
     .modal-loading { 
      top: 0; 
      left: 0; 
      position: fixed; 
      z-index: 999; 
      width: 100%; 
      height: 100%; 
      background-color: rgba(0,0,0,0.1); 
      display: none; 
     } 

     .modal-loading .loading { 
      width: 64px; 
      height: 64px; 
      margin: 200px auto; 
     } 
    </style> 
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
    <div class="modal-loading"><div class="loading"><img src="http://wz.sera5902.myjino.ru/loading.gif"></div></div> 
<?php 
// isset 
if (isset($_POST['search'])) { 
    // show var_dump 
    if ($member == SAPE_USER) { showPre($_POST); } 
    // try... 
    try 
    { 
     // vars 
     $sapeURLID  = $_POST['url_id']; 
     $sapeDepth  = $_POST['domain_level']; 
     $sapeInInG  = $_POST['indexed_in_google']; 
     $sapeOrder  = $_POST['order']; 
     $sapePLeve  = $_POST['page_level']; 
     $sapeSdays  = $_POST['search_days']; 
     $sapeKwdos  = $_POST['keyword']; 
     $sapeKwpla  = $_POST['keyword_placement']; 
     $sapeSdmoz  = $_POST['site_in_dmoz']; 
     $sapeExtLi  = $_POST['external_links']; 
     $sapePriFr  = $_POST['price_from']; 
     $sapePriTo  = $_POST['price_to']; 
     $sapeMajC1  = $_POST['mj_cf_1']; 
     $sapeMajC2  = $_POST['mj_cf_2']; 
     $sapeMajT1  = $_POST['mj_tf_1']; 
     $sapeMajT2  = $_POST['mj_tf_2']; 
     $sapePageN  = $_POST['page_number']; 
     // arrays 
     $zones = array(); 
     if (isset($_POST['zones'])) { 
      if (count($_POST['zones']) > 0) { 
       foreach ($_POST['zones'] as $key => $value) { 
        $zones[] = $value; 
       }   
      }   
     } 
     // arrays 
     $cats = array(); 
     if (isset($_POST['categories'])) { 
      if (count($_POST['categories']) > 0) { 
       foreach ($_POST['categories'] as $key => $value) { 
        $cats[] = $value; 
       }   
      } 
     } 
     // xml-rpc query 
     $userSearch  = $sape->search($sapeURLID, array("order"=>$sapeOrder,"domain_level"=>$sapeDepth,"domain_zones"=>$zones,"categories"=>$cats,"flag_blocked_in_google"=>$sapeInInG,"level_from"=>$sapePLeve,"days_old_whois"=>$sapeSdays,"words"=>str_replace(" ", "+", $sapeKwdos),"words_type"=>$sapeKwpla,"in_dmoz"=>$sapeSdmoz,"ext_links"=>$sapeExtLi,"pr_from"=>$sapePriFr,"pr_2"=>$sapePriTo,"mj_cf_1"=>$sapeMajC1,"mj_cf_2"=>$sapeMajC2,"mj_tf_1"=>$sapeMajT1,"mj_tf_2"=>$sapeMajT2), $sapePageN); 
     // is there any results? 
     if (count($userSearch) == 0) { 
      stderr("No results with those filters, try again with more options selected."); 
     }  
     // loop results 
     foreach ($userSearch as $val1) { 
       // ignore blank urls 
       if (!empty($val1['url'])) { 
        if ($member == SAPE_USER) { 
         echo "<pre>"; 
         echo "<br />"; 
         echo "<b>ID:</b> " . $val1['id']; 
         echo "<br />"; 
         echo "<b>URL:</b> " . $val1['url']; 
         echo "<br />"; 
         echo "<br />"; 
        } 
        foreach ($val1['pages'] as $key => $val2) { 
         $urlCheck = DB::getInstance()->selectOne(
          ' 
          SELECT DISTINCT site_sape_url, site_uri 
          FROM `sites` 
          WHERE `site_sape_url` = :site_sape_url 
          AND  `site_uri` = :site_uri', 
          [ 
           'site_sape_url' => $val1['url'], 
           'site_uri' => $val2['uri'] 
          ] 
         ); 
         // count check 
         if (!count($urlCheck)) { 
          // ten op for the site level 
          $level = ($val2['uri'] == "/") ? '1' : $val2['level']; 
          // get site ip 
          $ip = gethostbyname(parse_url($val1['url'], PHP_URL_HOST));      
          // insertion 
          DB::getInstance()->insert(
           'sites', 
          [ 
           'site_sape_id' => $val1['id'], 
           'site_sape_url' => $val1['url'], 
           'site_uri_id' => $val2['id'], 
           'site_uri' => $val2['uri'], 
           'site_uri_price' => $val2['price'], 
           'site_level' => $level, 
           'site_pages_in_google' => $val1['nof_pages_in_google'], 
           'site_ip' => $ip, 
           'site_added' => date('Y-m-d H:i:s') 
          ]);              
         }        
         //////////////////////////////////////////////////////////////////////////////////// 
         // have we already checked the link stats? 
/*      $already = DB::getInstance()->select("SELECT * FROM `metrics` WHERE `metrics_url`='".trim($val1['url'] . $val2['uri'])."'"); 
         if (!count($already)) { 
          // vars 
          $fURL = returnDomDetails(trim($val1['url'] . $val2['uri']));    
          // domdetailer 
          $domMajestic = json_decode($fURL); 
          if ($domMajestic) { 
            // avoid "PHP Notice: Trying to get property of non-object" warnings 
            DB::getInstance()->insert(
            'metrics', 
            [ 
            'metrics_user_id' => 1, 
            'metrics_url' => $metricsURL, 
            'metrics_moz_links' => $domMajestic->mozLinks, 
            'metrics_mozPA' => $domMajestic->mozPA, 
            'metrics_mozDA' => $domMajestic->mozDA, 
            'metrics_mozRank' => $domMajestic->mozRank, 
            'metrics_mozTrust' => $domMajestic->mozTrust, 
            'metrics_FB_comments' => $domMajestic->FB_comments, 
            'metrics_FB_shares' => $domMajestic->FB_shares, 
            'metrics_google_plus_one' => $domMajestic->google_plus_one, 
            'metrics_pinterest_pins' => $domMajestic->pinterest_pins, 
            'metrics_linkedin' => $domMajestic->linkedin, 
            'metrics_majesticLinks' => $domMajestic->majesticLinks, 
            'metrics_majesticRefDomains' => $domMajestic->majesticRefDomains, 
            'metrics_majesticCF' => $domMajestic->majesticCF, 
            'metrics_majesticTF' => $domMajestic->majesticTF, 
            'metrics_date' => date('Y-m-d H:i:s') 
            ]); 
          } 
         } */  
         ////////////////////////////////////////////////////////////////////////////////////       
         if ($member == SAPE_USER) { 
          echo "<br />"; 
          echo "<b>------------->Page ID:</b> " . $val2['id']; 
          echo "<br />"; 
          echo "<b>------------->Page:</b> " . $val2['uri']; 
          echo "<br />"; 
          echo "<br />"; 
         } 
        } 
        if ($member == SAPE_USER) { 
          echo "</pre>"; 
        } 
       } 
     } 
     // show var_dump 
     if ($member == SAPE_USER) { showPre($userSearch); } 
     // message 
     stdmsg('Search complete, view the results <a href="buy-links.php">here</a>.'); 
    } catch (SapeApiException $e) { 
      if ($e->getMessage() == "SAPE.RU: Search result is too big :o(") { 
       stderr('Your search query has too many results, try refining your search options to be more specific.'); 
      } else { 
       stderr($e->getMessage()); 
      } 
    } 
} 
// get the logged in users id 
$row = get_logged_in_users_details($member); 
// the ID 
$hID = $row['member_id']; 
?> 
    <div class="panel panel-primary"> 
     <div class="panel-heading">Search - To get a Link ID you need to create a project.</div> 
     <div class="panel-body"> 
      <form id="search-form" action="search.php" method="post" class="form-horizontal container-fluid" role="form"> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtLinkID" class="control-label">Link ID:</label> 
        </div> 
        <div class="col-sm-6"> 
        <select id="txtLinkID" name="url_id" class="form-control" required="required"> 
          <?php 
          $rows = DB::getInstance()->select('SELECT * FROM `projects` WHERE `project_member_id`='.$hID); 
          ?> 
          <?php foreach ($rows as $row) { ?> 
           <option value="<?php echo htmlspecialchars($row['project_sape_link_id']) ?>"><?php echo htmlspecialchars($row['project_sape_link_id']) ?></option> 
          <?php } ?> 
        </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtLevelDepth" class="control-label">Domain Level:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="txtLevelDepth" name="domain_level" class="form-control" required="required"> 
          <?php 
          $level = array(0 => "1",1 => "2",2 => "3"); 
          ?> 
          <?php foreach ($level as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtLevelDepth" class="control-label">Nesting Pages:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="txtLevelDepth" name="page_level" class="form-control" required="required"> 
          <?php 
          $nesting = array(0 => "page_level_1",1 => "page_level_2",2 => "page_level_3"); 
          ?> 
          <?php foreach ($nesting as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Categories:</label> 
        </div> 
        <div class="col-sm-6"> 
          <?php 
          $rows = DB::getInstance()->select('SELECT * FROM `categories`'); 
          ?> 
          <?php foreach ($rows as $row) { ?> 
           <input type="checkbox" name="categories[]" value="<?php echo htmlspecialchars($row['cat_sape_id']) ?>"> - <?php echo htmlspecialchars($row['cat_name']) ?><br> 
          <?php } ?> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Zones:</label> 
        </div> 
        <div class="col-sm-6"> 
          <?php 
          $rows = DB::getInstance()->select('SELECT * FROM `zones`'); 
          ?> 
          <?php foreach ($rows as $row) { ?> 
           <input type="checkbox" name="zones[]" value="<?php echo htmlspecialchars($row['zone_sape_id']) ?>"> - <?php echo htmlspecialchars($row['zone_name']) ?><br> 
          <?php } ?> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Indexed in Google:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="" name="indexed_in_google" class="form-control" required="required"> 
          <?php 
          $depth = array(0 => "Yes",1 => "No",2 => "Does not matter"); 
          ?> 
          <?php foreach ($depth as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Site in DMOZ:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="" name="site_in_dmoz" class="form-control" required="required"> 
          <?php 
          $dmoz = array(1 => "No", 0 => "Yes"); 
          ?> 
          <?php foreach ($dmoz as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Site Must Be older Than (in days):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="search_days" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Site Must Contain This Keyword:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="keyword" value="" class="form-control" size="40" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Keyword Should Be:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="" name="keyword_placement" class="form-control" required="required"> 
          <?php 
          $depth = array(0 => "On the page somewhere",1 => "In the <title>Keyword(s)</title> tags"); 
          ?> 
          <?php foreach ($depth as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">No More Than This Number of External Links On-Page:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="external_links" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Price (From):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="price_from" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Price (To):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="price_to" value="500" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="txtCR" class="control-label">Majestic CF (Min):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="mj_cf_1" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">Majestic CF (Max):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="mj_cf_2" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">Majestic TF (Min):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="mj_tf_1" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">Majestic TF (Max):</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" id="" name="mj_tf_2" value="0" class="form-control" size="40" required="required"/> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Order Results By:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="" name="order" class="form-control" required="required"> 
          <?php 
          $depth = array(9 => "Lowest price first",19 => "Highest price first",4 => "Category Descending",14 => "Category Ascending"); 
          ?> 
          <?php foreach ($depth as $key => $value) { ?> 
           <option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label"># Of Pages Of Results:</label> 
        </div> 
        <div class="col-sm-6"> 
         <select id="" name="page_number" class="form-control" required="required"> 
          <?php for ($x = 1; $x <= 5; $x++) { ?> 
           <option value="<?php echo $x ?>"><?php echo $x ?></option> 
          <?php } ?> 
         </select> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label" style="display: inline-block;">&nbsp;</label> 
        </div> 
        <div class="col-sm-6 text-right"> 
         <button type="submit" name="search" class="btn btn-default">Search</button> 
         <input type="hidden" name="hiddenID" value="<?php echo $hID; ?>" /> 
        </div> 
       </div> 

      </form> 
     </div> 
     <div class="panel-footer">Search for links using <b>your</b> criteria.</div> 
    </div> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $('#search-form').submit(function(){ 
      $('.modal-loading').fadeIn(); 
      var url = $(this).attr('action'); 
      $.post(url, $(this).serialize(), function(html){ 
       $('.modal-loading').fadeOut(); 
       var newDoc = document.open("text/html", "replace"); 
       newDoc.write(html); 
       newDoc.close(); 
      }); 
      return false; 
     }); 
    }); 
    </script> 
<?php 

include('includes/footer.php'); 

После «поиск» нажата, я хотел загрузку .gif, чтобы показать, что пользователь работает (это прекрасно видно) проблема заключается в том, что форма, кажется, не отправляет, if (isset ($ _ POST ['search'])) { не запускается по какой-то причине, может ли кто-нибудь увидеть что-нибудь, что я пропустил?

ответ

0

Это главная проблема с W3Schools и людьми, которые следуют за ним.

if (isset($_POST['search'])) { 

Никогда не отправлено! Или вызвано. Вам нужно проверить вкладку «Сеть» на все, что происходит с запросом POST.

Вы должны проверить с:

if (count($_POST) > 0) { 

Или что-то, что вы посылаете.

Смежные вопросы