0
votes

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:

view.ctp comments section

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.

Thank you,

1

1 Answers

1
votes

Use .load().

$('#article_comments').load('view.ctp #article_comments > *')