CAKEPHP - Submit comment and display flash message only using Ajax/Jquery
Problem: I would like to submit comments to an article using ajax without reloading the entire page.
I have a Comments controller and an Articles controller. In the Comments controller I will be using the Add function to insert comments into Db that is submitted thru the View action in the Articles.
Basically, when a user visits an article and wishes to submit a comment, the following happens:
- User inserts comments and clicks Submit in Article's view.ctp
- The View action in the Articles controller is called
- The action checks if Comments Data is being submitted and if it is, the Add action in the Comments controller is called to process it.
- And then the Article's view.ctp is reloaded
How do I go about adding Ajax to this process so that the only section reloaded is
<div id="article_comments">
...
</div>
in the Article's view.ctp?
EDIT ======================================================
Basically, this is what I have:
I think we the knowledge I've now acquired in both jQuery and CakePHP, I should be able to accomplish this. I will work on that, hopefully tonight.
开发者_JAVA技巧Thank you,
Use .load()
.
$('#article_comments').load('view.ctp #article_comments > *')
精彩评论