Take the 2-minute tour ×

I think CakePHPs JsHelper is pretty neat to use for AJAX form submissions. Normally you just set the DOM element to update with the new content and the JsHelper takes care of the rest. A normal submit button could look like:

echo $this->Js->submit('Submit', array(
    'update' => '#a-div',
    'url' => 'some-url'

Now, I want to update 2 or 3 different DOM elements and my AJAX response type will be JSON with 2 or 3 key pairs. So to my question.

How can I capture the JSON response data and pass THAT DATA to an independent callback function that I have written myself where I can parse the response and update the relevant DOM elements with the value pairs? What is the correct syntax for that? I realise I could probably skip using the JsHelper and create my own submission, but I don't want to do that in this instance.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I found the right answer:

echo $this->Js->submit(
  'Lägg en i varukorgen',
    'url' => array('controller' => 'products', 'action' => 'ajax_basket'),
    'id' => 'basket-add-submit',
    'success' => 'myFunction(data);',

At the success callback, data holds the JSON being returned.

share|improve this answer

Forget the JsHelper and write jquery code yourself.

share|improve this answer

Your Answer


