How to send additional data with an ajax response

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to send additional data with an ajax response

Poggenpohl, Daniel
Hello everyone,

we have a problem where we update some page with an ajax request, but need additional data to be sent with the ajax response. This additional data should then be consumed on the client side by an ajaxComplete event. Does anyone know how a Tapestry event method can return more than just getBody() in the response? We would need to return a response containing both the new body and a JSONObject for consumption.

Regards,
Daniel P.
Reply | Threaded
Open this post in threaded view
|

Re: How to send additional data with an ajax response

Thiago H de Paula Figueiredo
On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel  
<[hidden email]> wrote:

> Hello everyone,

Hi!

> we have a problem where we update some page with an ajax request, but  
> need additional data to be sent with the ajax response. This additional  
> data should then be consumed on the client side by an ajaxComplete  
> event. Does anyone know how a Tapestry event method can return more than  
> just getBody() in the response?

Why don't you use data attributes in the returned HTML instead?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to send additional data with an ajax response

Chris Poulsen
Ajax response renderer may also be a viable solution for returning multiple
things. I tend to prefer that over returning getBody() for exactly that
reason.

--
Chris


On Wed, Oct 28, 2015 at 2:05 PM, Thiago H de Paula Figueiredo <
[hidden email]> wrote:

> On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel <
> [hidden email]> wrote:
>
> Hello everyone,
>>
>
> Hi!
>
> we have a problem where we update some page with an ajax request, but need
>> additional data to be sent with the ajax response. This additional data
>> should then be consumed on the client side by an ajaxComplete event. Does
>> anyone know how a Tapestry event method can return more than just getBody()
>> in the response?
>>
>
> Why don't you use data attributes in the returned HTML instead?
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

AW: How to send additional data with an ajax response

Poggenpohl, Daniel
Hello,

do you have example code returning not only the body, but also additional data, for me?

Regards,
Daniel

-----Ursprüngliche Nachricht-----
Von: Chris Poulsen [mailto:[hidden email]]
Gesendet: Mittwoch, 28. Oktober 2015 22:16
An: Tapestry users
Betreff: Re: How to send additional data with an ajax response

Ajax response renderer may also be a viable solution for returning multiple things. I tend to prefer that over returning getBody() for exactly that reason.

--
Chris


On Wed, Oct 28, 2015 at 2:05 PM, Thiago H de Paula Figueiredo <
[hidden email]> wrote:

> On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel <
> [hidden email]> wrote:
>
> Hello everyone,
>>
>
> Hi!
>
> we have a problem where we update some page with an ajax request, but need
>> additional data to be sent with the ajax response. This additional data
>> should then be consumed on the client side by an ajaxComplete event. Does
>> anyone know how a Tapestry event method can return more than just getBody()
>> in the response?
>>
>
> Why don't you use data attributes in the returned HTML instead?
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: AW: How to send additional data with an ajax response

Thiago H de Paula Figueiredo
On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel  
<[hidden email]> wrote:

> Hello,
>
> do you have example code returning not only the body, but also  
> additional data, for me?

Have you even considered my suggestion of using data tags inside the  
rendered HTML to provide the data?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: How to send additional data with an ajax response

Chris Poulsen
I haven't checked out all of the callback types, but we often use the
javascript callback to do extra stuff on the calling page.

Something like:

ajaxResponseRenderer.addCallback( new JavaScriptCallback()
{
    @Override
    public void run( JavaScriptSupport javascriptSupport )
    {
        javascriptSupport.require( "<module-name>" ).invoke(
"<method-name>).with(
<data-to-return-must-match-invoked-module-method-signature);
    }
} );

This does not plug into the ajax complete event, but will be executed as
part of the call returning. There is a json callback as well, but I have
not looked into what is supposed to receive its return data.

--
Chris

On Thu, Oct 29, 2015 at 12:40 PM, Thiago H de Paula Figueiredo <
[hidden email]> wrote:

> On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <
> [hidden email]> wrote:
>
> Hello,
>>
>> do you have example code returning not only the body, but also additional
>> data, for me?
>>
>
> Have you even considered my suggestion of using data tags inside the
> rendered HTML to provide the data?
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

AW: AW: How to send additional data with an ajax response

Poggenpohl, Daniel
In reply to this post by Thiago H de Paula Figueiredo
Hello,

sorry, when I wrote the question I had totally forgotten about your post.
So you mean the HTML5 method of having, for example, a div element like this:
<div data-additionalData="myData"> ?

If you meant that, I haven't used this method yet for anything. Wouldn't that bloat the sent source if the additionalData is a big JSONArray? (I do not know anything about data tags yet, will inform myself)

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Thiago H de Paula Figueiredo [mailto:[hidden email]]
Gesendet: Donnerstag, 29. Oktober 2015 12:40
An: Tapestry users
Betreff: Re: AW: How to send additional data with an ajax response

On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <[hidden email]> wrote:

> Hello,
>
> do you have example code returning not only the body, but also
> additional data, for me?

Have you even considered my suggestion of using data tags inside the rendered HTML to provide the data?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

AW: AW: How to send additional data with an ajax response

Poggenpohl, Daniel
Hello again,

ah, of course I forgot to mention that our code should run in IE9, sadly. (I wouldn't prefer that). And IE9 doesn't seem to support data attributes.

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Poggenpohl, Daniel [mailto:[hidden email]]
Gesendet: Freitag, 30. Oktober 2015 10:45
An: Tapestry users
Betreff: AW: AW: How to send additional data with an ajax response

Hello,

sorry, when I wrote the question I had totally forgotten about your post.
So you mean the HTML5 method of having, for example, a div element like this:
<div data-additionalData="myData"> ?

If you meant that, I haven't used this method yet for anything. Wouldn't that bloat the sent source if the additionalData is a big JSONArray? (I do not know anything about data tags yet, will inform myself)

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Thiago H de Paula Figueiredo [mailto:[hidden email]]
Gesendet: Donnerstag, 29. Oktober 2015 12:40
An: Tapestry users
Betreff: Re: AW: How to send additional data with an ajax response

On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <[hidden email]> wrote:

> Hello,
>
> do you have example code returning not only the body, but also
> additional data, for me?

Have you even considered my suggestion of using data tags inside the rendered HTML to provide the data?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: How to send additional data with an ajax response

Thiago H de Paula Figueiredo
In reply to this post by Poggenpohl, Daniel
On Fri, 30 Oct 2015 07:45:18 -0200, Poggenpohl, Daniel  
<[hidden email]> wrote:

> Hello,

Hi!

> sorry, when I wrote the question I had totally forgotten about your post.
> So you mean the HTML5 method of having, for example, a div element like  
> this: <div data-additionalData="myData"> ?

Yep! I'd just add the attributes to some existing HTML element

> If you meant that, I haven't used this method yet for anything.

That's the method Tapestry 5.4 itself uses.

> Wouldn't that bloat the sent source if the additionalData is a big  
> JSONArray? (I do not know anything about data tags yet, will inform  
> myself)

Yes, but then your response would be big anyway, data in HTML attributes  
or in a JSON object.

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: How to send additional data with an ajax response

Thiago H de Paula Figueiredo
In reply to this post by Poggenpohl, Daniel
On Fri, 30 Oct 2015 07:48:11 -0200, Poggenpohl, Daniel  
<[hidden email]> wrote:

> Hello again,

Hi!

> ah, of course I forgot to mention that our code should run in IE9,  
> sadly. (I wouldn't prefer that). And IE9 doesn't seem to support data  
> attributes.

Data attributes are attributes like any other. IE9's JavaScript may not  
provide direct support for reading them, but jQuery and other JavaScript  
frameworks will cover that for you.

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]