mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
107 lines
3.6 KiB
HTML
107 lines
3.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
|
<title>JSON Data Over XHR</title>
|
|
|
|
<style type="text/css">
|
|
/*margin and padding on body element
|
|
can introduce errors in determining
|
|
element position and are not recommended;
|
|
we turn them off as a foundation for YUI
|
|
CSS treatments. */
|
|
body {
|
|
margin:0;
|
|
padding:0;
|
|
}
|
|
</style>
|
|
|
|
<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
|
|
<link rel="stylesheet" type="text/css" href="../../build/datatable/assets/skins/sam/datatable.css" />
|
|
<script type="text/javascript" src="../../build/yahoo-dom-event/yahoo-dom-event.js"></script>
|
|
<script type="text/javascript" src="../../build/connection/connection-min.js"></script>
|
|
<script type="text/javascript" src="../../build/json/json-min.js"></script>
|
|
<script type="text/javascript" src="../../build/element/element-min.js"></script>
|
|
<script type="text/javascript" src="../../build/datasource/datasource-min.js"></script>
|
|
<script type="text/javascript" src="../../build/datatable/datatable-min.js"></script>
|
|
|
|
<!--there is no custom header content for this example-->
|
|
|
|
</head>
|
|
|
|
<body class="yui-skin-sam">
|
|
|
|
|
|
<h1>JSON Data Over XHR</h1>
|
|
|
|
<div class="exampleIntro">
|
|
<p>This example populates a DataTable with data received via XHR from the Yahoo!
|
|
Local webservice.</p>
|
|
|
|
</div>
|
|
|
|
<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
|
|
|
|
<div id="json"></div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
YAHOO.util.Event.addListener(window, "load", function() {
|
|
YAHOO.example.XHR_JSON = function() {
|
|
var formatUrl = function(elCell, oRecord, oColumn, sData) {
|
|
elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
|
|
};
|
|
|
|
var myColumnDefs = [
|
|
{key:"Title", label:"Name", sortable:true, formatter:formatUrl},
|
|
{key:"Phone"},
|
|
{key:"City"},
|
|
{key:"Rating.AverageRating", label:"Rating", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true}
|
|
];
|
|
|
|
var myDataSource = new YAHOO.util.DataSource("assets/php/ylocal_proxy.php?");
|
|
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
|
|
myDataSource.connXhrMode = "queueRequests";
|
|
myDataSource.responseSchema = {
|
|
resultsList: "ResultSet.Result",
|
|
fields: ["Title","Phone","City",{key:"Rating.AverageRating",parser:"number"},"ClickUrl"]
|
|
};
|
|
|
|
var myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs,
|
|
myDataSource, {initialRequest:"query=pizza&zip=94089&results=10&output=json"});
|
|
|
|
var mySuccessHandler = function() {
|
|
this.set("sortedBy", null);
|
|
this.onDataReturnAppendRows.apply(this,arguments);
|
|
};
|
|
var myFailureHandler = function() {
|
|
this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
|
|
this.onDataReturnAppendRows.apply(this,arguments);
|
|
};
|
|
var callbackObj = {
|
|
success : mySuccessHandler,
|
|
failure : myFailureHandler,
|
|
scope : myDataTable
|
|
};
|
|
|
|
myDataSource.sendRequest("query=mexican&zip=94089&results=10&output=json",
|
|
callbackObj);
|
|
|
|
myDataSource.sendRequest("query=chinese&zip=94089&results=10&output=json",
|
|
callbackObj);
|
|
|
|
return {
|
|
oDS: myDataSource,
|
|
oDT: myDataTable
|
|
};
|
|
}();
|
|
});
|
|
</script>
|
|
|
|
<!--END SOURCE CODE FOR EXAMPLE =============================== -->
|
|
|
|
</body>
|
|
</html>
|