AJAX - Get entire outout of one block?
Permalink
Hello all,
Recently been introduced to Concrete5.. and all I can say so far is.. WOW.
I have been playing about with the development, and love the amount of documentation you guys have for everything! So far i've been able to find everything I have needed to, however, there is one thing I cannot seem to find.
I am working on a live(ish) chat block - I have it working, and a submit form, that adds a new message if the user is logged in, which is kindof okay, however I would love to instead use AJAX.
I was just wondering if its possible (if I create a tools script) if I can get that script to only return the output of 1 block, rather than the whole page?
Is that possible? And if so, how would I go about doing that?
Thanks,
Richard Anderson.
Recently been introduced to Concrete5.. and all I can say so far is.. WOW.
I have been playing about with the development, and love the amount of documentation you guys have for everything! So far i've been able to find everything I have needed to, however, there is one thing I cannot seem to find.
I am working on a live(ish) chat block - I have it working, and a submit form, that adds a new message if the user is logged in, which is kindof okay, however I would love to instead use AJAX.
I was just wondering if its possible (if I create a tools script) if I can get that script to only return the output of 1 block, rather than the whole page?
Is that possible? And if so, how would I go about doing that?
Thanks,
Richard Anderson.
Can you explain in a little more detail how this chat block is supposed to work? Do you mean that people go into edit mode and click "Edit" on the block? Or it's like a form that people fill out in the front-end (and you're using the "$this->action()" function for the form action with an action method in the block controller to process it)? Or are you trying to do this with the built-in "form" block? Or something else?
I'm trying to use jQuery to return only 1 single block (The output of my chat block.
EG:
User fills in a message in a textarea - They click submit - The message gets sent to my tool script, which adds the message to the database, the tools script then returns the HTML of the ENTIRE block, so that it can be "refreshed" without the entire page reloading.
I would just add the new message to the end - however, there might be a different template, therefore it would need to be hard coded which might not match the template.
It must be possible, surely.. Is there not a "$controll->generate()" function that returns the HTML?
Thanks,
Richard
EG:
User fills in a message in a textarea - They click submit - The message gets sent to my tool script, which adds the message to the database, the tools script then returns the HTML of the ENTIRE block, so that it can be "refreshed" without the entire page reloading.
I would just add the new message to the end - however, there might be a different template, therefore it would need to be hard coded which might not match the template.
It must be possible, surely.. Is there not a "$controll->generate()" function that returns the HTML?
Thanks,
Richard
I think if you have the form pass the block id to the ajax responder (the tools file) -- put it in a hidden field or something -- then in the tools file you can do this:
Block::getByID($blockId)->display();