Skip to content
Johannes Geppert edited this page Jun 27, 2015 · 1 revision

Howto handle JSON results

Samples

AJAX link that handle an JSON result with an onSuccessTopic

This sample works with an JSON result that returns an array of customers. The json action is the same like in the grid example.

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
  <head>
    <sj:head/>
    <script type="text/javascript">
$(document).ready( function() {
    $.subscribe('handleJsonResult', function(event,data) {
	$('#result').html("<ul id='languagesList'></ul>");
	var list = $('#languagesList');
		$.each(event.originalEvent.data, function(index, value) { 
			list.append('<li>'+value+'</li>\n');
		});
    });
});    
    </script>        
  </head>
  <body>
	<div id="result">Click on the link bellow.</div>
	<s:url var="jsonurl" action="jsonlanguages"/> 

	<sj:a id="ajaxjsonlink" 
		href="%{jsonurl}" 
		dataType="json"
		onSuccessTopics="handleJsonResult"
		button="true" 
		buttonIcon="ui-icon-gear"
	>
  </body>
</html>
Clone this wiki locally