开发者

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:

  1. User inserts comments and clicks Submit in Article's view.ctp
  2. The View action in the Articles controller is called
  3. 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.
  4. 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:

CAKEPHP - Submit comment and display flash message only using Ajax/Jquery

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 > *')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜