Ajax & PHP

Ajax & PHP

milos87popovicmilos87popovic Posts: 1Questions: 0Answers: 0
edited April 2013 in General
Hi 2 all. I have web site for dogs selling, and I use a datatables (www.prodajapasa.rs), but I have a lot of dog ads on my site, and site is loading slow. Is there a possibility that the customer via Ajax, pulling data from the MySQL database? Has anyone done it and how hard is it?

Replies

  • rage10940rage10940 Posts: 48Questions: 0Answers: 0
    edited April 2013
    Via Ajax?

    These are the 3 API functions you need to look into :

    fnReloadAjax -> Asynchronous Ajax Calls

    sAjaxSource -> The actual file whether it be a php file that echo's JSON, a txt file that gets updated with JSON also I recommend using http://jsonlint.com/ so you can validate that your JSON is correct!

    sAjaxDataProp -> If your JSON array is not named the default "aaData" then you MUST explicitly state the name of the array you are trying to use.

    This is useful if you just want one txt file or one php file echo'ing different data array -> this would allow you to pick and chose which array you want to use.

    A usage example is like so :

    [code]
    $(document).ready(function()
    {
    var table1 = $('#waiting').dataTable(
    {
    "sPaginationType": "full_numbers",
    "bJQueryUI": true,
    "iDisplayLength": 10,
    "aLengthMenu": [5, 10],
    "sAjaxDataProp": "waiting", // This is taking the "waiting" array
    "sAjaxSource": '<?php echo base_url();?>studentqueue_controller/ajaxcall', // The path (url) to get my data source
    "bDeferRender": true, // You should try to use this as much as possible -> helps with performance!
    "bAutoWidth": false,
    "aoColumns":
    [
    {"mdata": "id",
    "sWidth": "7%",
    "mRender": function(data, full)
    {
    var div = '';
    var url = '' + '' + '' + '' + data + '';
    }
    },
    {"mdata": "first"},
    {"mdata": "last"},
    {"mdata": "SECOND",
    "sWidth": "1%"
    },
    {"mdata": "reason"},
    {"mdata": "studentcomments"},
    {"mdata": "aidyear",
    "sWidth": "1%"
    },
    {"mdata": "counselorcomments"}
    ]
    });
    setInterval(function() { // This initiates the asynchronous Ajax calls
    table1.fnReloadAjax(null, null, true);
    }, 1000);
    });

    [/code]

    Please take a look at my code commenting as well for more information on how / why I am using what I am using. Hopefully this helps!
This discussion has been closed.