Saturday, April 28, 2012

Interacting with a cakephp rest service using jquery - problem with PUT

Hi all,

Building a simple tool which uses a cakephp rest service. The client application is the webpage generated by the application, and it reacts to user input such as dragging and dropping things around.

I've extended the jquery ajax helper methods to include methods for PUT and DELETE, and these are triggering just fine.

The problem is I am unable to get the data back to cakephp to do anything with it.

heres the javascript which triggers everything off:

            $('div.content-block').droppable({
               drop: function(event, ui)
               {
                  $(this).children('ul').append(ui.draggable);
                  // perform the PUT on the db...  
                  var pilotID = ui.draggable.attr('id').split('-')[1]
                  var squadID = $(this).attr('id').split('-')[1];
                 
                  $.put('pilots/'+pilotID+'.json',
                  {
                     "squad_id" : squadID
                  }, function() {
                     alert('success');
                  }).error(function(){
                     alert('error');
                  }, 'json');


as you can see, it is performing a PUT request on the pilots controller which is setup up with default resource map, parse extensions and request handler. Dragging and dropping a pilot from one squad to another correctly triggers a HTTP PUT request, however inspecting $this->request->data and $this->request->input('json_decode') both return empty arrays.

I'd appreciate assistance from anyone who has successfully gotten jquery to interact with a cakephp rest api.

Cheers :)

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: