0

After searching for a long time I've decided to just ask it here, since the things I found either don't work(or I can't get them to work ;)) - or require me to change things on my server, which I would like to avoid.

I want below function to show the output after each result, so the function doesn't have to be loaded first, which takes a long time. My idea, as you can see below, was to try this with jQuery(1.8.2).

It doesn't work and I simply can't get it to work. Is there a better way to do this? Did I make a mistake somewhere causing it not to work?

If you need additional information, please ask.

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

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

update : solved!

so, what went wrong? -> the php function in core.inc.php referred to a incompatible with jQuery 1.8.2 lib ('qTip2'). Thanks for the support!

<?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
}
}
?>
3
  • What is your code doing? You need to explain what you are trying to do as well as just listing your code. Commented Oct 12, 2012 at 19:50
  • The PHP-side is waiting for server responses for a whois/dns lookup. The waiting time is way to long, people start to refresh, etc. So the idea is to output every result asap (per result)- to let customers know there is something going on on the background. Commented Oct 13, 2012 at 0:34
  • Now, the API that I use has the option to do a single request at a time. The jQuery does not seem to be posting and writing the results with the above code, and with this current setup the PHP-results take to long for a for()-loop Sorry for not explaining, & many thanks for the help! Commented Oct 13, 2012 at 0:45

1 Answer 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   }
    }
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It got me hopes up. Ill try to tweak this and post the results here. Until now - no luck with the jQuery-loop..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.