锁定老帖子 主题:dojo and ajax
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-05-14
最后修改:2010-08-06
XHR
has limitations. The big one is that
dojo.xhrGet function init(){ dojo.addOnLoad(init);
url: URL to server endpoint. load: Optional. Process what server return.
content: Optional. Contains properties with string values. These properties will be serialized as name1=value2 and passed in the request.
form: the form to submit.(url和form二选一) preventCache: Optional. Default is false. If true, then a "dojo.preventCache" parameter is sent in the request with a value that changes with each request (timestamp). Useful only with GET-type requests. sync: Optional. false is default. Indicates whether the request should be a synchronous (blocking) request.(为true则会等这个request处理完才会继续执行) timeout: Optional. Milliseconds to wait for the response. If this time passes, the then error callbacks are called. dojo.xhrPost
All
Dojo XHR methods are bi-directional. The only difference is the method. Using Submit the form <form id=”loginForm”> Name:<input type=”text” id=”firstName”/> </form>
add in some
JavaScript to submit the form by using
var formSubmit=function(e){ e.preventDefaut(); //prevent form submit dojo.xhrPost({ url: “ajaxServlet”, form : “mainForm”, handleAs : “text”, handle : function(data, args){ ………… } }); }; dojo.addOnLoad(function({ var theForm = dojo.byId(“loginForm”); dojo.connect(theForm, “onclick”, formSubmit); })); Getting text back from the server is nice,
but the really great stuff comes when you start passing JavaScript objects
around. Using a different
如何在server端取得数据 content: {a: 11, b: 22} String p1 = request.getParameter("a");
dojo.io.iframe 一般是用来上传文件。
<form id="myForm" enctype="multipart/form-data" action="uploadServlet"> Name: <input type="text" name="name"/> File: <input type="file" name="theFile"/> <button onclick="sendForm();">Submit</button> </form> dojo.io.iframe实际上和dojo.xhr使用是相同的,不同的只是iframe可以用来上传文件
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-05-15
很有用的函数!!
|
|
返回顶楼 | |
浏览 4270 次