简体   繁体   English

从cakephp视图传递一个JavaScript对象到控制器

[英]passing an javascript object from cakephp view to controller

I am developing a website using cakephp, and I'd like to pass a javascript object in view back to the controller. 我正在使用cakephp开发一个网站,并且希望将视图中的javascript对象传递回控制器。 I know that using a form could be easier but I need to do this customized. 我知道使用表单可能会更容易,但是我需要对此进行自定义。

So here's the object ('annotation' and 'article_id' are real column names in the database, annotation and article_id are both variables containing data): 因此,这是对象(“ annotation”和“ article_id”是数据库中的真实列名,annotation和article_id都是包含数据的变量):

var postdata = {
    'annotation' : annotation,
    'article_id' : article_id
};

What method in the view should I use? 我应该使用哪种视图方法? Is it .post? 是.post吗?

And how should I program the corresponding controller to correctly receive the object and extract data from it? 我应该如何编程相应的控制器以正确接收对象并从中提取数据?

您可能想要执行ajax请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM