On Mon, 10 Mar 2014 17:10:23 -0300, George Christman
<gchrist...@cardaddy.com> wrote:
AjaxDemo.js
define(["jquery"], function($) {
int = function(spec) {
var title= $( "h2" ).attr("id", spec.clientId);
$("body").append(title);
//Action to update title however I do not know how to return a
response nor am I sure if I ned to pass other params back.
$("button").bind("click", function() {
$.ajax({
url: spec.url
});
});
}
You're already passing the URL you got from
ComponentResources.createEventLink(), so you're in the right path already.
You already did almost everything. You don't need to pass any other
parameters back for Tapestry to handle the AJAX request, but, of course,
you may need to pass some information for you event handler. This would be
done by adding a 'data' variable to your call to $.ajax:
$.ajax({
url: spec.url,
data: {
param1: 'param1 value',
param2: 'param2 value'
}
}).done(function(data) {
// do something with the value returned in your event handler method
window.alert('New title: ' + data.title);
});
Here's the jQuery AJAX documentation: http://api.jquery.com/jQuery.ajax/
// I completely do not understand how to return a response without
the
use of a tapestry zone.
Object onAjaxDemo() {
return "Updated Title";
}
Just return an JSONObject, JSONArray or JSONLiteral with the information
you want to send back. In this case, I think the best option is to return
new JSONObject("title", "Updated title") and, in the JavaScript part, get
the 'title' property of the returned object.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org