【问题标题】:Submitting form via ajax, one way or two ways?通过ajax提交表单,一种还是两种方式?
【发布时间】:2011-04-23 04:10:40
【问题描述】:

这两个选项哪个更好:

1. $.post( '/ajax/action', function(data) { doResult(); }  );

*This option has to receptors: ajax.php and action.php*

2. $.post( '/action', { typerequest: 'ajax' }, function (data) { doResult(); }

*This option has only 1 receptor: action.php (if typerequest exists, returns ajax result)*

没有 ajax 的表单看起来像:

<form action="/action">

【问题讨论】:

    标签: php jquery ajax post action


    【解决方案1】:

    这两者之间没有区别,真的。选择对你来说更容易的。

    我认为独立处理 Ajax 脚本更容易(即选项 1)。另一个脚本将不得不自己打印一整页。这意味着您必须有条件地显示它(例如通过 typerequest),并且您最终会在条件句中包装很多东西。

    但实际上任何一种方式都很好。选择你最舒服的。保持一致即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多