views:

37

answers:

2

I'm writing a little webapp for mobile.

There is a form asking for a particular item and its details, users should be able to insert one or more items with their details.

If it was a normal webapp I'd use ajax with a link "add one" just like gmail does for attachments. On mobile I think it's not a good idea using ajax, so I used "i'm done" and "add more" button which load a new page and the rest of the list is saved server side. This means that for each new item a user need to reload the page, it is slow and it may costs more to my users. Is there a better way to do this?

+1  A: 

You shouldn't need to save it server-side; just do a regular postback and append new HTML on the server -- but store the list-so-far in the returned HTML.

So e.g. the simplified HTML would originally be:

<form>
  <input name="info0" type="text" value="" />
  <input name="done" type="submit" value="I'm done" />
  <input name="more" type="submit" value="Add another" />
</form>

If the user types in "foo" for "info0" and selects "Add another", the returned HTML from the postback will now be this:

<form>
  <input name="info0" type="text" value="foo" />
  <input name="info1" type="text" value="" />
  <input name="done" type="submit" value="I'm done" />
  <input name="more" type="submit" value="Add another" />
</form>

The key is you wouldn't be saving anything on the server side until the user was done. You can do removals in the same way, e.g. with checkboxes, or a button next to each input.

Aseem Kishore
Storing temporaney data serverside is not a problem, makig user reload a bigger page is, as they are mobile users and they may be charged more (and the page is slower to download).
Andrea Ambu
+1  A: 

Sorry, I misinterpreted the question. I don't see why using AJAX would be a bad idea -- as long as it was unobtrusive AJAX, using the principles of progressive enhancement. The whole idea of PE is that it'll work on all devices.

  1. Code up your non-AJAX solution using a postback method like you have.
  2. Add in unobtrusive AJAX that prevents the postback from occuring and does it all async.

For users that have JS enabled, it'll work nicely. For those that don't, it'll still work nicely, just with postbacks.

Aseem Kishore
This is how I'd do anyway on a normal webapp. But how the not async part should be done?
Andrea Ambu