0

搜索了很长时间后,我决定在这里问一下,因为我发现的东西要么不起作用(或者我无法让它们起作用;)) - 要么要求我更改服务器上的东西,我想避免。

我希望下面的函数在每个结果之后显示输出,因此不必先加载该函数,这需要很长时间。正如您在下面看到的,我的想法是用 jQuery(1.8.2) 来尝试这个。

它不起作用,我根本无法让它工作。有一个更好的方法吗?我在某处犯了错误导致它不起作用吗?

如果您需要更多信息,请询问。

<?php
print_r($_POST);


if(isset($_POST['p']) && isset($_POST['domain']) && isset($_POST['option']))
{   error_reporting(0);
define('INCLUDE_CHECK',true);
require('admin/API/class_api.php');
require('admin/functions/core.inc.php');

    $dom = explode('.',$_POST['domain']);
    $dom = $dom[0];
    $ext = array('nl','be','eu','net','com','org','biz','info','tk','ws','gr','me','cc','in','gs','name','ch','co','tv','ru','bz','li','lu','pl','se','vg','cx','tl','im','sg','ms','sh','io','mu','fm','am','xxx','ag','sc','nf','md');

    if ($_POST['loop']==40)
     { print 'Laatste loop dus .. STOP : .'.$ext[41]; }
    else
     { print 'Loop: '.$_POST['loop'].' - zoek op : .'.$ext[$_POST['loop']];
       ?>
       <script>
        $.post('test.php', { p:'full', domain:dom, option:opt, loop:'<?php echo $_POST['loop']+1; ?>'},
        function(data){
          $('#domresults2').css('display','block').html(data);
          $('#domloading').css('display','none');
        });
       </script>
       <?php
     }

}
?>




//Start JS
<script>
$('#domsubmit.complete').click( function() {
  var dom = escape($('#domsearch').val());
  var opt = escape($('#option').val());

  $('#domresults2').css('display','none').html('');
  $('#domloading').css('display','inline');

  $.post('test.php', { p:'full', domain:dom, option:opt, loop:0},
     function(data){
       $('#domloading').css('display','none');
       $('#domresults2').css('display','block').html(data);
   });

return false;
});
</script>
//end JS

////////////////////////

更新:解决了!

那么,出了什么问题?-> core.inc.php 中的 php 函数引用了一个与 jQuery 1.8.2 不兼容的库('qTip2')。感谢您的支持!

<?php
print_r($_POST);

if (isset($_POST['p']) && isset($_POST['domain']) && isset($_POST['option'])) {
error_reporting(0);
define('INCLUDE_CHECK', true);
require('admin/API/class_api.php');
require('admin/functions/core.inc.php');

$dom = explode('.', $_POST['domain']);
$dom = $dom[0];
$ext = array('nl','be','eu','net','com','org','biz','info','tk','ws','gr','me','cc','in','gs','name','ch','co','tv','ru','bz','li','lu','pl','se','vg','cx','tl','im','sg','ms','sh','io','mu','fm','am','xxx','ag','sc','nf','md');

$loop = $_POST['loop'];
DomCheck($_POST['domain'],$ext[$_POST['loop']]);

if ($loop != count($ext)) {
$loop++;?>
  <script type="text/javascript">
        var opt = '<?php echo $_POST['option']; ?>';
        var dom = '<?php echo $_POST['domain']; ?>';
        $.post('test.php', { p:'full', domain:dom, option:opt, loop:'<?php echo $loop; ?>'},
        function(data){
            $('#domresults2').css('display','block').append(data);
            <?php if ($loop < count($ext)) {
                      echo "$('#domloading').css('display','none');";
                  } ?>
        });
    </script>
<?php
}
}
?>
4

1 回答 1

1

One thing you need to understand is that PHP executes on the server and JavaScript (jQuery) executes on the client.

This means that by the time jQuery starts executing, PHP is done.

However, I don't see a loop anywhere in your code. I think this is more of what you wanted. You're not doing a "PHP loop using jQuery," you're outputting jQuery code in a PHP loop:

<?php
if (isset($_POST['p']) && isset($_POST['domain']) && isset($_POST['option'])) {
    error_reporting(0);
    define('INCLUDE_CHECK', true);
    require('admin/API/class_api.php');
    require('admin/functions/core.inc.php');

    $dom = explode('.', $_POST['domain']);
    $dom = $dom[0];
    $ext = array('nl','be','eu','net','com','org','biz','info','tk','ws','gr','me','cc','in','gs','name','ch','co','tv','ru','bz','li','lu','pl','se','vg','cx','tl','im','sg','ms','sh','io','mu','fm','am','xxx','ag','sc','nf','md');

    foreach ($_POST['loop'] as $loop) {
        if ($loop == 40) {
            print "Laatste loop dus .. STOP : .{$ext[41]}";
        } else {
            print "Loop: {$loop} - zoek op : .{$ext[$loop]}";
?>      <script>
            $.post('test.php', { p:'full', domain:dom, option:opt, loop:'<?php echo $loop; ?>'},
            function(data){
                $('#domresults2').css('display','block').html(data);
                $('#domloading').css('display','none');
            });
        </script>
<?php   }
    }
}
?>
于 2012-10-12T19:44:46.043 回答