2

I have 3 pages ie main_page.php , ajx_page1.php and ajx_page2.php

And I am using $.post request in main_page.php and sent to ajx_page1.php. After this ajx_page1.php send $.post request to ajx_page2.php. And i have added an image below for better understanding...

Problem

The request are working good and fast on my localhost, and when i run this on live server it taking almost 4-6 seconds of time. And this is most horrible time lapse.

Is there any other method for posting a ajax request within a page to child-child pages as shown in images below.

And also ajx_page2.php retrieve the data from database.. and and other pages are pulling data from their ajx-child pages

Even CSS and jQuery are not working..

Code

Main_page.php

$.post("ajx_page1.php", {parameters}, function(return_data){
    $("#container").html(return_data);
});

ajx_page1.php

$.post("ajx_page1.php", {parameters}, function(return_data){
    $("body").html(return_data);

});

ajx_page2.php

    `some condition and logical data from database`

enter image description here


Updated file details

Main_page.php

<div id="content_region" class="center">

    <div class="a_job_pre_action clear">
    <ul class="a_jj_ul">
        <li class="j_act_1 j_act" ><a href="" >JOB DETAIL</a> </li>
        <li class="j_act_2 j_act" ><a href="" >STAFF SHORTLISTED</a> </li>
        <li class="j_act_3 j_act" ><a href=""  >CLIENT SHORTLISTED</a> </li>
        <li class="j_act_4 j_act" ><a href="">CONFIRM FOR INTERVIEW</a> </li>

        <?php if ($_SESSION['user_type'] == "admin" or $_SESSION['user_type'] == "manager"): ?>
            <li class="j_act_5 j_act" ><a href="" >INVOICES</a> </li>
        <?php endif; ?>

        <li class="j_act_6 j_act" ><a href="" >CONTACT CLIENT</a> </li>
    </ul> <!-- a_jj_ul -->
    </div> <!-- a_job_pre_action -->

    <div class="clear a_job_action_result">



    </div>


<script>

    $(document).ready(function(){

    $(".j_act_1 a").click(function(){


        $.post("ajx_page1.php", {job_id : j_job_id}, function(return_data32){
            $(".a_job_action_result").html(return_data32);
        });
    });




    });

</script>

ajx_page1.php

<select class="a_sel" name="sel_staff">
    <?php get_all_staff_options(); ?>
</select>

// and some other data too.


<script>

    $(document).ready(function(){

    $(".ajx_select_status").change(function(){
       var j_job_status = $(this).val();
        var j_job_code = "<?php echo $curr_job_data['job_code']; ?>";


        $.post("ajx_page.php", {job_status : j_job_status, job_code : j_job_code}, function(return_data32){
            alert(return_data32);
        });


    });



    });

</script>

ajx_page2.php

full pure php code here
Rafee
  • 3,975
  • 8
  • 58
  • 88
  • 5
    Most likely this isn't related to jQuery at all, considering the difference is the server/network and not the client. Keep in mind when working from localhost that you have a 0ms latency between you and your server. – Kevin B Oct 03 '12 at 14:18
  • 5
    Your requests may also appear to perform faster if you perform them all at once rather than in a chain. Doing it in a chain means the request time is going to be the combined duration of all three requests rather than the length of the longest. That of course won't work if one depends on the next, just a thought. – Kevin B Oct 03 '12 at 14:26
  • 2
    Sounds to me like a complaint about your net connection or your hosting. – Orbling Oct 03 '12 at 14:26
  • 2
    @Rafee: The only factors that will slow your post down comparing your localhost and your hosting, are the latency and speed of the connection to your hosting, and the performance of your hosting server. – Orbling Oct 03 '12 at 14:33
  • just want to know how are you getting the script from ajx_page1.php and executing it ? – GajendraSinghParihar Oct 04 '12 at 16:25
  • using `require('styles_scirpts.php')` in `main_page.php`. – Rafee Oct 04 '12 at 16:49
  • @Champ And also called these scripts in `ajx_page1.php` but css and scripts are not working... Specially `thickbox` a modal pop in iframe.. – Rafee Oct 04 '12 at 16:50
  • I'm a hundred percents sure, that problem in php script - could you show it? Maybe the database is much bigger then yours on localhost? – Vadim Ivanov Oct 06 '12 at 10:22
  • @Rafee is it important to issue the ajax calls serially or would parallel ajax calls work in your case? Your image does not make that clear. – richardaday Oct 06 '12 at 19:25
  • These contains heavy page code. and update it with few – Rafee Oct 10 '12 at 19:53

3 Answers3

3

well. When I have a page running slow. I do the following 4 things:

(I use chrome and hit F12 )

  • Add timer start and stop printouts on your three php pages, especially around database calls.
  • click on 'audits' and run it
  • click on 'timeline' and run it
  • click on 'profiles' and run it

it will tell you exactly what's slow on your page. The usual suspects are your database calls so check the time printouts to confirm database performance.

---optional--- it sounds like you're always pulling in the css for the further ajax calls. Pull the css into the main page until you get your speed back.

DefyGravity
  • 5,681
  • 5
  • 32
  • 47
  • whether you use .html() or .empty().append() depends on any manipulation you plan on doing to ajax returns. [proof here](http://stackoverflow.com/questions/3015335/jquery-html-vs-append) – DefyGravity Oct 06 '12 at 19:21
  • google chrome developer tools -'audit' [Google tutorial video](http://www.youtube.com/watch?v=Qsv6NjnWFLI) – DefyGravity Oct 06 '12 at 20:17
0

I see here the architecture problem,

Why you not just made simple .js standalone file, which will do that ajax requests, check success: function() {} parameter of $.post()

The way to solve problems make me assume that php code also overloaded by strange solutions which causes slowdowns.

Also keep in mind - javascript is client side and if you trying to make this way any ACL, then work out your dao. :)

zb'
  • 8,071
  • 4
  • 41
  • 68
0

It would be wise to find a more efficient way to manipulate your data. My first thought was to avoid using the third php script by including the code from ajax_page2 to ajax page 1, or even combining the php code in ajax_page_1 and making ajax calls to the page itself

If you are not allowed or able to do so, try to cache your results in order to speedup your process, one way to do so is by using memcached or even a custom script: e.g http://www.profilepicture.co.uk/caching-api-responses-php/

TheodoreV
  • 304
  • 4
  • 17