Viewed   63 times

I have a PHP function on my site which takes a couple of seconds to complete. This holds the whole page up which I don't want.

Would it be possible with jquery to call this PHP function after the page has loaded and display the results in a div? Also to display an ajax loader image until the PHP function has completed?

I've been looking at but can't seem to get it to work.

Would someone be able to help?

Thank you



AJAX does the magic:


    $.ajax({ url: 'script.php?argument=value&foo=bar' });

Thursday, October 20, 2022

I think you've got almost everything. The callback function you have under success needs an argument which stands for the results from search.php

     success: function(res) {
             $('#result').html("<br><br><br><br><br><br><br><br><br><br><div class='center'><img src='img/loader.gif' /></div>").hide().fadeIn(2500, function() {
                 $('#result').html(res + "<br /><br /> Finished");

res is everything outputted be search.php. Echo, stuff outside of php tags, etc Anything you'd see if you loaded search.php itself.

I don't know if you wanted 'Finished' to still be there. Take it out if you dont.

Tuesday, October 18, 2022

I solved my problem with a friend's help.

Basically what we've done.

We create a div with the "php echo":

<div id="intervalo-manha"><?php echo intervalo_manha(); ?></div>

Then we've hiden it with css:

<style type="text/css">
    #intervalo-manha {
        display: none;

After this we just called the div at jQuery function:

var newRow = $("<tr style='margin-left:-60px'>...<td>" + $("#intervalo-manha").html() + "</td></tr>");

I never thought that it could be so easier. :)

Thank you for everyone who gave me tips and suggestions.


Monday, August 15, 2022

You need to quote p_user_id:

echo '<td class="btn-action"><a href="javascript:void(0);" 
          onClick="record_delete(''.$p_user_id.'')" class="btn-delete">
      <i class="fa fa-times" aria-hidden="true"></i></a></td>';
Wednesday, October 12, 2022

i think your problem may be in ajax code since you are using formData object . try append the message variable with it

$('#submit').on('click', function(){

  var fd = new FormData(this);
  fd.append('message ',$('#message').val());

    url:"<?php echo site_url('home/send_chat');?>",    
    data: fd,  
    cache: false,
    contentType: false,
    processData: false,   
    success: function(data){                 
    error: function(xhr, status, error) {
Saturday, November 12, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :