Ajax 面试题与答案
Question: How do I submit a form or a part of a form without a page refresh?Answer: When creating a form make sure that the "form" element "onSubmit" attribute is set to a JavaScript function that returns false.<form onSubmit="doAJAXSubmit();return false;" > <input type="text" id="tf1" /> <input type="submit" id="submit1" value="Update"/> > You can also submit data by associating a function with a form button in a similar way. <form onSubmit="doAJAXSubmit();return false;" > <input type="text" id="tf1" /> <input type="button" id="button1" onClick="doAJAXSubmit()" value="Update"/> > Note that the form "onSubmit" attribute is still set. If the user hits the enter key in the text field the form will be submitted so you still need to handle that case. When updating the page it is recommend you wait to make sure that the AJAX update of the form data was successful before updating the data in the page. Otherwise, the data may not properly update and the user may not know. I like to provide an informative message when doing a partial update and upon a successful AJAX interaction I will then update the page. |
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
这有帮助吗? 是 否
用户评价最有帮助的内容:
- What's AJAX ?
- Is it possible to set session variables from javascript?
- Who's Using Ajax ?
- Did Adaptive Path invent Ajax? Did Google? Did Adaptive Path help build Google's Ajax applications?
- What is the difference between proxied and proxyless calls?