On Mon, Mar 10, 2014 at 9:10 PM, George Christman <gchrist...@cardaddy.com>wrote:
> I'm trying to create a custom implementation of bootstrap/modal where I can > dynamically load the content via ajax while modal is open. My use case is > iterate through a series of warnings while clicking the submit action. I'd > like to dynamically inject those warnings via ajax, however I do not know > how to write a custom ajax request in tapestry. > > What I think I know, > > I'm assuming I need to create an event link and pass it into my js like so > and then setup a jquery ajax request. I do not know how to properly set up > the request so that it returns a response. > > In my little demo below, I'd like to try and update the title with an ajax > request to tapestry's backend. > > public class AjaxDemo { > > static final String EVENT_NAME = "ajaxdemo"; > > @Parameter(required = true) > private String clientId; > > void afterRender() { > Link link = resources.createEventLink(EVENT_NAME); > JSONObject spec = new JSONObject("id" ,clientId, "url", > link.toString()); > > jsSupport.require("ajaxDemo").with(spec); > } > > } > > > 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 > }) > .done(function(data){ console.log('response:'+data); > }); > }); > > } > > return int; > > }); > > Tapestry Page. > > public class Demo { > > // I completely do not understand how to return a response without the > use of a tapestry zone. > Object onAjaxDemo() { > > return "Updated Title"; > return new JSONObject("key", "value); //etc etc. > } > > } > > If there is documentation or examples on how to do this, please feel free > to share them with me, otherwise I'd really appreciate anybody who has the > time to finish the above example and explain what I'm missing. This kind of > example might work well with Geoff's jumpstart. > See code filled inline. What you're asking is completely non related to tapestry and pure jquery code. Please see the documentation here https://api.jquery.com/jQuery.ajax/ If you want to use zones that's a different question. Might be simpler in terms of rendering full content on the server and not just returning a JSONObject. > > > Thanks, > George > > > > > > > > > > > > > > > > > > -- > George Christman > www.CarDaddy.com > P.O. Box 735 > Johnstown, New York >