开发者

Classic post request vs ajax request

I have a table with some items. I select one and when i click a button i want to send its id in the server side and based on that id to create some excel file. To send the id from the client should i use a classic post(create a form, assign to id a hidden, submit it and destroy it) or should i use $.post from jqu开发者_Go百科ery(or any other ajax) When to use each?


First of all, your application should be able to work even for people who don't have Javascript support enabled in their browser -- which means your application should work without any Javascript being required ; which means your should implement the form / hidden field / post method.


Then, when this work, you can enhance user-experience with a bit of Ajax : instead of using the form you created, just send an Ajax request ; the goal being to not do a full page-load, and have something that's more user-friendly.

But note that, if the user disable's Javascript, your application should fall-back to the first solution.


To make things short :

  • Create a basic HTML implementation, that just "works".
  • Then, enhance user-experience with Javascript / Ajax.


AJAX is usually used to submit a form (or make any other kind of request) and do something with the value it returns without having to reload the page (e.g. update an element on the current page).

If I understand you correctly, you want to return a file to download.

In that case, submitting a form the normal way (maybe with a target="_blank" so the current window won't be lost) and returning the file (including the right headers so the save as... dialog appears) seems the more straight forward way.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜