cakephp和jquery提交数据post
我正在将 jquery 与 cakephp 一起使用,我需要将一些数据发布到控制器的更新功能。我需要将它分开,以便它在 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 |
,所以它全部显示在“名称”列下。
这是我的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");
}
});
});
});
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的元素 #ID1 到 #ID7 不具有所需格式的
name
属性是否有充分的理由?如果您使用
echo $this->Form->input('Answer.1.body')
呈现输入字段,则会自动发生这种情况。如果您不喜欢FormHelper
默认提供的内容,可以通过多种方式自定义输出。然后,您可以使用 jQuery("#ID1,#ID2...").serialize() 之类的方法来帮助将数据发布回服务器。看来您需要让 jQuery 和 CakePHP 框架为您做更多的工作:)
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 whatFormHelper
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 :)