You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2014/12/15 16:16:48 UTC
Returning json when request is non xhr
Hi,
I have 2 applications (different servers):
1) html + js
2) Tapestry5
Now I tried to do an ajax request (jquery) from application 1 to
application 2 where I want to return some json back to application 1.
But because cross domain get requests do not use XHR I get following
error in application 2:
Return type org.apache.tapestry5.json.JSONObject can not be handled.
So how can I return json if the request is not XHR ?
Re: Returning json when request is non xhr
Posted by Chris Poulsen <ma...@nesluop.dk>.
You could try to add your own ComponentEventResultProcessor<JSONObject> -
However I do not know whether this interferes with the built in tapestry
stuff for ajax - If that is the case you could probably return a different
type of json.
Check (StreamResponse/StreamResponseResultProcessor) in tapestry sources
for an example of how to add the code
--
Chris
On Mon, Dec 15, 2014 at 4:16 PM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:
>
> Hi,
>
> I have 2 applications (different servers):
> 1) html + js
> 2) Tapestry5
>
> Now I tried to do an ajax request (jquery) from application 1 to
> application 2 where I want to return some json back to application 1.
> But because cross domain get requests do not use XHR I get following
> error in application 2:
>
> Return type org.apache.tapestry5.json.JSONObject can not be handled.
>
> So how can I return json if the request is not XHR ?
>
Re: Returning json when request is non xhr
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 15 Dec 2014 13:16:48 -0200, Nathan Quirynen
<na...@pensionarchitects.be> wrote:
> Hi,
Hi!
>
> I have 2 applications (different servers):
> 1) html + js
> 2) Tapestry5
>
> Now I tried to do an ajax request (jquery) from application 1 to
> application 2 where I want to return some json back to application 1.
> But because cross domain get requests do not use XHR I get following
> error in application 2:
>
> Return type org.apache.tapestry5.json.JSONObject can not be handled.
>
> So how can I return json if the request is not XHR ?
Just wrap the JsonObject or JsonArray in a StreamResponse when the request
isn't AJAX:
if (request.isXHR()) {
return jsonObject;
else {
return new TextStreamResponse("application/json", jsonObject.toString());
}
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org