0

I am using jquery with cakephp and I need to post some data to a update function of controller. I need it to be separated so that it would look like this in fiddler

Name                   |    Value
data[Answer][1][body]  |    John DC
data[Answer][2][body]  |    Company
data[Answer][3][body]  |    Title
data[Answer][4][body]  |    Country
data[Answer][5][body]  |    Email
data[Answer][6][body]  |    Phone
data[Answer][7][body]  |    test




Name                                                                                                                   |  Value
    data[Answer][1][body]:John DC,data[Answer][2][body]:Company,data[Answer][3][body]:Title,data[Answer][4][body]:Country,data[Answer][5][body]:Email,data[Answer][6][body]:Phone,data[Answer][7][body]:test    |

So it all shows up under Name column.

Here is my ajax

$j(document).ready(function() { 
    $j('#form').click( function () {
        alert("hi");
        $j.ajax({

             type: 'post',    

             data:  
                    "data[Answer][1][body]:" +  $j('#ID1').val() + 
                    ",data[Answer][2][body]:" + $j('#ID2').val() + 
                    ",data[Answer][3][body]:" + $j('#ID3').val() + 
                    ",data[Answer][4][body]:" + $j('#ID4').val() +
                    ",data[Answer][5][body]:" + $j('#ID5').val() +
                    ",data[Answer][6][body]:" + $j('#ID6').val() +
                    ",data[Answer][7][body]:" + $j('#ID7').val(),

             url: "/mypage/update",
             success: function(){
                alert("Done");
              }
            });

     });  
 });

thanks

1
  • solved it using json. but now running into a new prob will post in a new question Commented Apr 1, 2011 at 23:34

1 Answer 1

1

Is there a good reason your elements #ID1 to #ID7 don't have the name attribute in the format you need?

This will happen automatically if you use echo $this->Form->input('Answer.1.body') to render your input fields. If you don't like what FormHelper gives you by default there are many ways to customize the output.

You can then use something like jQuery("#ID1,#ID2...").serialize() to help post your data back to the server. Seems like you need to let both the jQuery and CakePHP frameworks do more of the work for you :)

Sign up to request clarification or add additional context in comments.

1 Comment

I just saw your earlier question as well. Unless I misunderstand what you are doing I would take another look at the CakePHP cookbook, eg book.cakephp.org/view/1390/Automagic-Form-Elements. I only resort to using fiddler in exceptional situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.