将javascript对象从cakephp视图传递到控制器 [英] passing an javascript object from cakephp view to controller

查看:113
本文介绍了将javascript对象从cakephp视图传递到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cakephp开发一个网站,我想把一个javascript对象传回控制器。我知道使用表单可以更容易,但我需要做这个自定义。

I am developing a website using cakephp, and I'd like to pass a javascript object in view back to the controller. I know that using a form could be easier but I need to do this customized.

这里的对象('annotation'和'article_id'数据库,注释和article_id都是包含数据的变量):

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):

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

我应该使用视图中的什么方法?是.post吗?

What method in the view should I use? Is it .post?

我应该如何编程相应的控制器正确接收对象并从中提取数据?

And how should I program the corresponding controller to correctly receive the object and extract data from it?

推荐答案

您可能想要执行 ajax 请求。

You probably want to do an ajax request.

这篇关于将javascript对象从cakephp视图传递到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆