问题
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.
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
};
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?
回答1:
You probably want to do an ajax request.
来源:https://stackoverflow.com/questions/7456940/passing-an-javascript-object-from-cakephp-view-to-controller