Thursday, 15 March 2012

javascript - How to get AJAX response before sending to template using DATATABLES? -


I am implementing a log table in my admin panel and I have used the datatable plugin. I have created an AJAX in my data, but I do not know how the response can be received before sending it to the table.

I have this in jquery:

  & lt; Script type = "text / javscript" & gt; $ (Document) .ready (function () {$ ('# log-pageview') .on ('xhr .dt', function (e, settings, json) {$ ('# status'). Html (json. Status)}) .DateTell ({"processing": true, "server side" is true: "AJAX": "/secure/logs/visits.php?log_get=1"})}} & lt; / Script> I have this in my HTML:  
   table id = "log-pageview" class = "display" selection = "0" width = "100%" & Gt; & lt; thead & gt; & gt; & gt; & gt; & lt; th & gt; Log ID & lt; / th> & lt; th & gt; User ID & lt; / th & gt; & Lt; th & gt; IP address & lt; / th & gt; & lt; th & gt; Date visited & lt; / th & gt; & lt; / tr & gt; & lt; / thead & gt; ; & Lt; tfoot & gt; & lt; tr & gt; & lt; Th & gt; Log ID & lt; / th> & lt; th> User ID  & lt; th & gt; IP Address & lt; / th & gt; & Lt ; Th & gt; Date visited & lt; / th & gt; & lt; / tr & gt; & lt; / tfoot & gt; & lt; / table & gt; & lt; div id = "status" & Gt; & lt; / div & gt;  

In my server side PHP, I have this.

  function get_pageview () {$ host = mysql_connect ('localhost', 'avjunky_2', '1qaz2wsx') or die (mysql_error ()); Mysql_set_charset ('utf8', $ host); // Added for character encoding, this has been made global for tasks / tasks added by interesting / ** $ db = mysql_select_db ('avjunky_2', $ host) or die (mysql_error ()); $ Log_array = array (); $ Log_data = array (); $ Get_all_logs = mysql_query ("SELECT id, logged_id, ip_address, date_viewed from avjunky_pageview", $ host); ($ Row_logs = mysql_fetch_array ($ get_all_logs)) {$ log_data [] = array ('id' = & gt; $ row_logs ['id'], 'log in_id' => $ row_logs ['logged_id'], ' Ip_address' = & gt; $ row_logs ['ip_address'],' date_ viewed '= & gt; $ row_logs [' date_viewed ']); } $ Total_count = count ($ log_data); $ Log_array = array ('draw' => 1, 'recordsTotal' => $ total_count, 'recordfilter' = & gt; $ total_count, 'data' = & gt; $ log_data); Echo json_encode ($ log_array); } If (isset ($ _ GET ['log_get'])) {get_pageview (); }  

On the server side, I created this kind of Jason:

  {"draw": 1, "recordsTotal": 2, "record filters ": 2," data ": [{" id ":" 3 "," log in_id ":" 7 "," ip_address ":" 122.2.55.11 "," date_ viewed ":" 2015-03-16 10:10 : "," "ID", "{0}," "id" 2, "data": [{"id": "3", "logged_id", "data": "" "," record ": 1, Record Total ": 2," Record Filter ": 2," Data "": "7", "ip_address": "122.2.55.11", "Date_view": "2015-03-16 10:10:42"}, {"Id": "2", "logged_id": "8", "ip_address": "122.2.55.11", "date_view": "2015-03-17 00:05:40"}]}  

I do not know where I went wrong I developed a developer tool The Torkwork tab has been examined and it seems that Ajax is not calling the URL.

In my AJX I also tried to call the response from the URL in this way.

< / P>

But this does not load data as well.

First of all, use For xhr.dt datatable> 1.10 should be used.

Second, the data should be of the following structure. 2, "data filter": [["3", "7", "122.2.55.11" , "2015-03-16 10:10:42"], ["2", "8", "122.2.55.11", "2015-03-17 00:05:40"]]} < / Pre>

this is a


No comments:

Post a Comment