How to implement ajax post submission in cakephp

i have surfed the net trying to implement ajax post submission in cakephp but to no avail, how can i achieve this functionality, just like the one on twitter and how do i update the post automatically whenever there is a new record? this is my post code:

public function add($id = null) { if ($this->request->is('post')) { $this->request->data['Post']['user_id'] = $this->Session->read(''); $this->Post->create(); if ($this->Post->save($this->request->data)) { $this->Session->setFlash(__('The post has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The post could not be saved. Please, try again.')); } } $users = $this->Post->User->find('list'); $this->set(compact('users')); }

and here is my post form:

<?php echo $this->Form->create('Post'); ?> <fieldset> <legend><?php echo __('Add Post'); ?></legend> <?php echo $this->Form->input('title'); echo $this->Form->input('content'); ?> </fieldset> <?php echo $this->Form->end(__('Submit')); ?>

-------------Problems Reply------------

Try this for Ajax post submission.

Replace your submit button code with the following:

<?php echo $this->Ajax->submit('SUBMIT',
'url' => array(
'controller' =>'your_controller',
'action' =>'your_function'
'update' =>'update_section_id',

Jquery required:

$('#yourFormId').on('submit', function(event){


type: "post",
url: "formSubmit", //your form submission route
data: {data1: $('input[name="yourInputName"]').val(), //you can add more here},
dataType: "json",
cache: false,
success: function(result){
//Do something with returned data



public funtion formSubmit(){
$this->autoRender = false;

$data = $this->request->data;
//Do something with data
//If save or update successful
$response = array('status' => 'success', 'msg' => 'your msg');
return json_encode($response);


Category:javascript Views:0 Time:2018-09-14

Related post

  • Ajax form submission in cakephp 2011-09-12

    I have used ajax form submission in cakephp echo $ajax->submit('Submit', array('url'=> array('controller'=>'projects', 'action'=>'add_comment'), 'update' => 'feedback_'.$value['contest_submission']['id'])); After i submitting the form

  • How to implement related posts feature without tagging each post? 2009-05-19

    We have 2 text fields ('post_text' & 'post_slug') in our database. Let's say, post_text = "Hello World!", so its post_slug = "hello-world". How to implement related posts feature without tagging each posts operating only existing fields? (PHP, My

  • How to implement an equipment system in CakePHP 2009-09-10

    I'm attempting to create a CakePHP based web game mostly for practice as well as for the fun of it, but am running into a conundrum trying to figure out an equipment system. I have an Items table that contains all the possible information about an it

  • How to implement Facebook Post Type objects in GAE? 2011-05-15

    I a new programmer and trying to implement a facebook type "feed" in my application. Like Whenever a user do some changes in his profile his linked profiles will get to know that in the form of news feed. But I am stuck on that as I thought whenever

  • How to implement sticky posts in Wordpress? 2011-06-20

    wordpress support stick post function. and store the stick info in wp_options table named sticky_posts and will autoload. so I dig into the sql created by wp, (add log = /tmp/mysql.log in my.cnf). open the index page of wordpress. sticky posts shows

  • How to implement facebook like notification on cakephp? 2011-10-08

    does somebody knows how to implement facebook like notification? the idea is to put notification on the tabs parallel to the changes made in the database without refreshing the site? if a data is added to the database, the site should react on it. th

  • How to implement ajax voting application using the Grails Framework? 2009-05-03

    any good samples of code or articles that can help? --------------Solutions------------- There isnt a plugin that can do "voting", because voting is quite domain specific. It would be easy to implement a simple voting app in grails. I'd write it here

  • How to queue ajax posted form data when connection is down 2010-11-14

    I have a kiosk web page that users use to sign in at an event. On the page there is a form with a name and email input. To prevent slow responses due to connection problems I have set up the ui to send asynchronous ajax posts. The problem is that the

  • How to solve ajax post while hosting a mvc 3 application 2011-10-15

    I am hosting a MVC3 application in IIS7. The aplication got hosted but ajax post is not working in the application. Could Anyone help on this? Thanks in advance. --------------Solutions------------- You have hardcoded the urls in your javascript, hav

  • How to prevent AJAX post to send data if there is any validation error in form? 2011-12-23

    I am trying to submit data using Jquery AJAX (using the following script) and it is working alright but the problem is it submits data even though there are some validation errors in my forms. I am using jQuery validation plug-in 1.7 to validate my f

  • JQuery Ajax Post submission - with conditional validation before ajax post or pop alert 2012-02-19

    Attempting what would appear to be a simple pre ajax-post validation against a short form. This is working correctly and posting data perfectly until adding an attempt at a conditional value check against it. JQuery is adding the values to the form o

  • How to do AJAX POST in Django 1.0 without cross-site request forgery error? 2012-03-27

    I am using jQuery to do an AJAX POST, but get a CSRF error. I assume this is because the CSRF cookie isn't sent to the client to send back. Is there a way I can fix this in Django 1.0? --------------Solutions------------- Yuji's suggestion pointed me

  • jQuery AJAX post submission to a PHP script multiple times 2011-09-12

    I am trying to do a form submission without having the page reload. It works the first time, but when I try and do a second submission the page is refreshed. I would like to be able to do several submissions with the new data propagating into the cur

  • how to implement ajax popup with jquery in mvc view? 2009-07-22

    Suppose I have a view to display the list of employee like: <table> <% foreach (var item in Model) { %> <tr><td> <img name=<%="disp"> alt="" src="../../Content/Disp.gif" /> </td></tr> <% { %

  • How to use AJAX Post to invoke ASP.NET MVC Controller action and return new View? 2010-08-16

    I am working a site in ASP.NET MVC where the user is presented with a calendar, and clicking on a particular calendar date invokes the following function: function selectHandler(event, data) { var myRequest = new Request.HTML({ url: '/Calendar/EventL

  • How to make https post request in Cakephp 2010-11-23

    I have requirement where app has to make REST API calls over HTTPS POST. I am new to cakephp. I was thinking if I could do https calls using httpsocket. I appreciate any help. Thanks. --------------Solutions------------- If you have PHP's Curl module

  • How to implement user-friends relationship in cakephp? 2010-12-30

    I am new to cakephp. I am working on my Social network project.I am having users and friends relationship concept. I am having problem in sending friend request and accepting ..... I am not understanding how to start on this concept... If anybody wor

  • How to implement HTTP Post chunked upload of a big file using java httpclient? 2011-03-07

    I have an enormous file to upload and server on other side does support chunked upload. Is there any example of how exactly to do that? Or there is some other library which do that? --------------Solutions------------- Using HttpClient 4 (From Apache

  • How to implement ajax using Django and Jquery? 2011-05-31 .... (r'^blog/post/$', post), .... View code: def post(request): if request.method == 'POST': post, created = Post.objects.get_or_create( title=request.POST.get("title"), text=request.POST.get("text"), ) post_titles = [post.title for post in

  • Django: how to distinguish AJAX POST request? 2011-08-11

    I have a form that gets submitted using jQuery's .post(). In the corresponding view function, is there a way that I can use to determine that the requested received is AJAX? I have seen code snippet dated back to 2006, which uses request.GET.has_key(

  • jQuery - How to assign ajax post response to a variable 2011-11-23

    var jqxhr = $.post("/cms/menu_pagesave", { page_id: pageID, name : value_td, url : value_url }, function(data) { }) .success(function(response, textStatus, jqXHR){ if (response) { menupageID = response; console.log(response); } }); I've got the corre

  • How to implement Ajax back button simulation without href 2011-12-13

    So my entire site runs off of an index.php page and the content loads dynamically with many AJAX calls depending on what the user wants to do. I want to use the back button but currently I cannot. I have read some great tutorials and scoured over som

  • how to use ajax post to send data to a php file in phonegap? 2012-01-22

    im trying to do a ajax port to a php file, and it seems that is doesn't want to send the data. i have a android project using phone gap library and it looks like if i go a get it works: $(document).ready(function () { $.ajax({ type: 'GET', url: 'http

  • How to implement ajax and jquery into html 2012-02-17

    I asked a question before on how to add show/hide function to a div and render it exactly when a link is clicked. (The original question) I received an answer to use jquery and ajax together to do this. Here is the code I received: function unhide(){

  • How to Implement Ajax to display some content in php? 2009-08-18

    I want to create a page which displays some contents when left navigation menu is clicked. For Eg. When MY FAVOURITE VIDEOS is clicked then the list of the users favourite videos should be displayed on the right side using AJAX. Help me -------------

Copyright (C), All Rights Reserved.

processed in 1.504 (s). 12 q(s)