Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX调用在本地工作,但不在子域上工作_Javascript_Php_Jquery_Ajax_Submit - Fatal编程技术网

Javascript AJAX调用在本地工作,但不在子域上工作

Javascript AJAX调用在本地工作,但不在子域上工作,javascript,php,jquery,ajax,submit,Javascript,Php,Jquery,Ajax,Submit,我已经写了一个小程序,它正在用simplehtmldom从一个网站上抓取一些数据。 它在我的本地主机上工作得很好,但是当我将它上传到服务器的子域时,它会给出一个错误500 我正在使用AJAX调用对表单进行提交,并使用submit.php文件进行检查 您可以在此处查看实时版本: 您只需在表单字段中输入数字 谢谢你的帮助 HTML表单 <form id="ecoop-tarifrechner" method="post"> <div class="col-md-6"&g

我已经写了一个小程序,它正在用simplehtmldom从一个网站上抓取一些数据。 它在我的本地主机上工作得很好,但是当我将它上传到服务器的子域时,它会给出一个错误500

我正在使用AJAX调用对表单进行提交,并使用submit.php文件进行检查

您可以在此处查看实时版本: 您只需在表单字段中输入数字

谢谢你的帮助

HTML表单

<form id="ecoop-tarifrechner" method="post">
      <div class="col-md-6">
        <div class="form-group">
          <input type="text" class="form-control" name="verbrauchkwh" id="verbrauchkwh" placeholder="Verbrauch des Kunden">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="text" class="form-control" name="plzkunde" id="plzkunde" placeholder="PLZ des Kunden">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="number" class="form-control" name="ecoop_preis_brutto_waerme" id="ecoop_preis_brutto_waerme" step=0.01 placeholder="ecoop brutto Arbeitspreis Wärme">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <input type="number" class="form-control" name="ecoop_preis_brutto" id="ecoop_preis_brutto" step=0.01 placeholder="ecoop brutto Arbeitspreis">
        </div>
      </div>

      <button type="submit" class="btn btn-default">Jetzt vergleichen</button>

    </form>
submit.php

<?php

/* update your path accordingly */
include_once 'assets/simple_html_dom.php';
include_once 'functions.php';


if( $_POST ){

$verbrauch = $_POST['verbrauchkwh'];
$plz = $_POST['plzkunde'];
$ecoop_preiskwh_waerme = $_POST['ecoop_preis_brutto_waerme'];
$ecoop_preiskwh = $_POST['ecoop_preis_brutto'];
$ecoop_grundpreis = 107.76;

$link = "https://www.check24.de/strom/result/?c24api_zipcode={$plz}&c24api_totalconsumption={$verbrauch}&c24api_customertype=private&c24api_eco=no&c24api_considerdiscounts=no&c24api_maxbonusshare=no&c24api_companyevaluation_positive=75&c24api_guidelinematch=yes&c24api_contractextension=12&c24api_cancellationperiod=30&c24api_contractperiod=12&c24api_paymentperiod=month&c24api_onlinesubscription=no&c24api_priceguarantee=guarantee_price&c24_priceguarantee_months=12&c24api_eco_type=normal&pid=24&c24_from_result_page=1";

$ecoop_kostenjahr = (($ecoop_preiskwh*$verbrauch)/100)+$ecoop_grundpreis;
$ecoop_kostenjahr_waerme = (($ecoop_preiskwh_waerme*$verbrauch)/100)+$ecoop_grundpreis;

// Create DOM from URL
$html = file_get_html($link);

// Find all article blocks
foreach($html->find('.c24-result-row-energy') as $konkurrent) {
  $item['anbieter']   = $konkurrent->find('.c24-provider-logo', 0)->alt;
  $item['tarifname']  = $konkurrent->find('.c24-tariffname', 0)->plaintext;
  $item['preiskwh']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 7)->plaintext;
  $item['grundpreis']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 13)->plaintext;
  $item['gesamtkosten']  = $konkurrent->find('.c24-result-price', 0)->plaintext;
  $item['preisgarantie']  = $konkurrent->find('.c24ResultsTableListBold span', 0)->plaintext;
  $item['vertragslaufzeit']  = $konkurrent->find('.c24-result-informations li span', 5)->plaintext;
  $konkurrenten[] = $item;
}

// var_dump($konkurrenten);

?>

<div class="container">
  <div class="row">
    <table class="table table-striped table-responsive">
        <tr>
            <th>Anbieter</th>
            <th>Stromtarif</th>
            <th>Preis/kWh (brutto/netto)</th>
            <th>Grundpreis/Jahr</th>
            <th>Gesamtkosten/Jahr</th>
            <th>Ersparnis/Jahr</th>
            <th>Preisgarantie</th>
            <th>Vertragslaufzeit</th>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Strom</td>
          <td><?= $ecoop_preiskwh ?> (<?= $ecoop_preiskwh_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Wärme</td>
          <td><?= $ecoop_preiskwh_waerme ?> (<?= $ecoop_preiskwh_waerme_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr_waerme ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>

        <? foreach ($konkurrenten as $checked) : ?>
         <tr>
           <td><?= $checked['anbieter']; ?></td>
           <td><?= $checked['tarifname']; ?></td>
           <td><?= $checked['preiskwh']; ?></td>
           <td><?= $checked['grundpreis']; ?></td>
           <td><?= $checked['gesamtkosten']; ?></td>
           <td><?= (priceToDouble($checked['gesamtkosten']))-$ecoop_kostenjahr ?> €</td>
           <td><?= str_replace('Preisgarantie: ', '', $checked['preisgarantie']) ?></td>
           <td><?= str_replace('Vertragslaufzeit: ', '', $checked['vertragslaufzeit']) ?></td>
         </tr>
         <? endforeach; ?>
    </table>
  </div>
</div>


<?php
}

安比特
斯特龙塔里夫
Preis/kWh(布鲁托/内托)
格伦德普里斯/加尔
Gesamtkosten/Jahr
厄斯帕尼斯/贾尔
Preisgarantie
Vertragslaufzeit
生态合作社
生态风暴
()克拉/千瓦时
()欧元/Jahr
€
31.12.2020
12单体1。加尔-达纳赫1莫纳特
生态合作社
ecoop Wärme
()克拉/千瓦时
()欧元/Jahr
€
31.12.2020
12单体1。加尔-达纳赫1莫纳特
€

响应为500那么它必须是php端的某个东西。不在ajax调用切换php错误报告中,因此您会得到一个信息错误:ajax工作正常,请检查您的后端代码服务器上的php版本是什么?在5.4版本之前,以下内容适用:PHP还允许在live server上启用短标记吗?
<?php

/* update your path accordingly */
include_once 'assets/simple_html_dom.php';
include_once 'functions.php';


if( $_POST ){

$verbrauch = $_POST['verbrauchkwh'];
$plz = $_POST['plzkunde'];
$ecoop_preiskwh_waerme = $_POST['ecoop_preis_brutto_waerme'];
$ecoop_preiskwh = $_POST['ecoop_preis_brutto'];
$ecoop_grundpreis = 107.76;

$link = "https://www.check24.de/strom/result/?c24api_zipcode={$plz}&c24api_totalconsumption={$verbrauch}&c24api_customertype=private&c24api_eco=no&c24api_considerdiscounts=no&c24api_maxbonusshare=no&c24api_companyevaluation_positive=75&c24api_guidelinematch=yes&c24api_contractextension=12&c24api_cancellationperiod=30&c24api_contractperiod=12&c24api_paymentperiod=month&c24api_onlinesubscription=no&c24api_priceguarantee=guarantee_price&c24_priceguarantee_months=12&c24api_eco_type=normal&pid=24&c24_from_result_page=1";

$ecoop_kostenjahr = (($ecoop_preiskwh*$verbrauch)/100)+$ecoop_grundpreis;
$ecoop_kostenjahr_waerme = (($ecoop_preiskwh_waerme*$verbrauch)/100)+$ecoop_grundpreis;

// Create DOM from URL
$html = file_get_html($link);

// Find all article blocks
foreach($html->find('.c24-result-row-energy') as $konkurrent) {
  $item['anbieter']   = $konkurrent->find('.c24-provider-logo', 0)->alt;
  $item['tarifname']  = $konkurrent->find('.c24-tariffname', 0)->plaintext;
  $item['preiskwh']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 7)->plaintext;
  $item['grundpreis']  = $konkurrent->find('.c24EnergyPriceLayer tbody tr td', 13)->plaintext;
  $item['gesamtkosten']  = $konkurrent->find('.c24-result-price', 0)->plaintext;
  $item['preisgarantie']  = $konkurrent->find('.c24ResultsTableListBold span', 0)->plaintext;
  $item['vertragslaufzeit']  = $konkurrent->find('.c24-result-informations li span', 5)->plaintext;
  $konkurrenten[] = $item;
}

// var_dump($konkurrenten);

?>

<div class="container">
  <div class="row">
    <table class="table table-striped table-responsive">
        <tr>
            <th>Anbieter</th>
            <th>Stromtarif</th>
            <th>Preis/kWh (brutto/netto)</th>
            <th>Grundpreis/Jahr</th>
            <th>Gesamtkosten/Jahr</th>
            <th>Ersparnis/Jahr</th>
            <th>Preisgarantie</th>
            <th>Vertragslaufzeit</th>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Strom</td>
          <td><?= $ecoop_preiskwh ?> (<?= $ecoop_preiskwh_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>
        <tr class="ecoop-blue">
          <td>ecoop</td>
          <td>ecoop Wärme</td>
          <td><?= $ecoop_preiskwh_waerme ?> (<?= $ecoop_preiskwh_waerme_netto ?>) Ct./kWh</td>
          <td><?= $ecoop_grundpreis ?> (<?= $ecoop_grundpreis_netto ?>) €/Jahr</td>
          <td><?= $ecoop_kostenjahr_waerme ?> €</td>
          <td></td>
          <td>31.12.2020</td>
          <td>12 Monate 1. Jahr - danach 1 Monat</td>
        </tr>

        <? foreach ($konkurrenten as $checked) : ?>
         <tr>
           <td><?= $checked['anbieter']; ?></td>
           <td><?= $checked['tarifname']; ?></td>
           <td><?= $checked['preiskwh']; ?></td>
           <td><?= $checked['grundpreis']; ?></td>
           <td><?= $checked['gesamtkosten']; ?></td>
           <td><?= (priceToDouble($checked['gesamtkosten']))-$ecoop_kostenjahr ?> €</td>
           <td><?= str_replace('Preisgarantie: ', '', $checked['preisgarantie']) ?></td>
           <td><?= str_replace('Vertragslaufzeit: ', '', $checked['vertragslaufzeit']) ?></td>
         </tr>
         <? endforeach; ?>
    </table>
  </div>
</div>


<?php
}