开发者

Submitting form via ajax, one way or two ways?

What's better of this two options:

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

*This option has to receptors: ajax.php and action.ph开发者_开发百科p*

or

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

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

Form without ajax looks like:

<form action="/action">


No difference between those two, really. Pick whatever is easier for you.

I think it is easier to have Ajax scripts handled independently (that is option 1). The other script is going to have to print out a whole page on its own. That means you have to conditionally display it (e.g. by typerequest) and you end up wrapping a lot of stuff in conditionals.

But really either way is fine. Pick whatever you are most comfortable with. Just be consistent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜