From d419c4ef6645cc177f8e45198f77a17d6f75b1e7 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Sat, 23 Apr 2011 07:00:25 +0100 Subject: [PATCH] New: JSONP example to show how it might be done - 4746 --- examples/server_side/jsonp.html | 188 +++++++++++++++++++++++++ examples/server_side/scripts/jsonp.php | 174 +++++++++++++++++++++++ 2 files changed, 362 insertions(+) create mode 100644 examples/server_side/jsonp.html create mode 100644 examples/server_side/scripts/jsonp.php diff --git a/examples/server_side/jsonp.html b/examples/server_side/jsonp.html new file mode 100644 index 00000000..e2d32704 --- /dev/null +++ b/examples/server_side/jsonp.html @@ -0,0 +1,188 @@ + + + + + + + DataTables example + + + + + + +
+
+ DataTables server-side processing example with JSONP +
+ +

Preamble

+

JSONP is a method of using JSON data from any server, regardless of XSS protection that modern browsers use. It is very useful for being able to retrieve JSON data from any domain name you choose and is easy to integrate with DataTables, thanks to jQuery's Ajax handler, as shown in this example.

+ +

Live example

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Rendering engineBrowserPlatform(s)Engine versionCSS grade
Loading data from server
Rendering engineBrowserPlatform(s)Engine versionCSS grade
+
+
+ + +

Initialisation code

+
$(document).ready(function() {
+	$('#example').dataTable( {
+		"bProcessing": true,
+		"bServerSide": true,
+		"sAjaxSource": "scripts/jsonp.php",
+		"fnServerData": function( sUrl, aoData, fnCallback ) {
+			$.ajax( {
+				"url": sUrl,
+				"data": aoData,
+				"success": fnCallback,
+				"dataType": "jsonp",
+				"cache": false
+			} );
+		}
+	} );
+} );
+ + +

Other examples

+

Basic initialisation

+ + +

Advanced initialisation

+ + +

Data sources

+ + +

Server-side processing

+ + +

API

+ + +

Plug-ins

+ + + +

Please refer to the DataTables documentation for full information about its API properties and methods.

+ + + +
+ + \ No newline at end of file diff --git a/examples/server_side/scripts/jsonp.php b/examples/server_side/scripts/jsonp.php new file mode 100644 index 00000000..a5d96ed2 --- /dev/null +++ b/examples/server_side/scripts/jsonp.php @@ -0,0 +1,174 @@ + intval($_GET['sEcho']), + "iTotalRecords" => $iTotal, + "iTotalDisplayRecords" => $iFilteredTotal, + "aaData" => array() + ); + + while ( $aRow = mysql_fetch_array( $rResult ) ) + { + $row = array(); + for ( $i=0 ; $i \ No newline at end of file