duanba4942 2013-12-10 07:05
浏览 41
已采纳

使用AJAX和方法POST提交表单

I have a difficulty in implementing an MVC system.
I have a simple comment system, which makes the record when sent via POST or via AJAX.

a) Should I separate the 2 controllers in Comment_Ajax and Comment_Post
b) or should I just keep a controller and and check the sent method (is_ajax()) to perform the necessary actions.

Form method 'Post' redirects to the page of the post and form method 'Ajax' only makes a reload in the comments.

  • 写回答

2条回答 默认 最新

  • duanbixia7738 2013-12-10 08:11
    关注

    I would go with version b, keeping related methods together. Keep DRY: Don´t Repeat Yourself.

    What you are doing are 2 actions (methods/functions) of one controller, which is pefectly valid MVC. Usually a controller has one action "render" (display page if no parameters are present), and can have multiple actions like save, update, submit, render_ajax etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度