前端之家收集整理的这篇文章主要介绍了
dojo/request/xhr,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html> <html > <head> <link rel="stylesheet" href="demo/claro.css"> <script>dojoConfig = {par
SEOnLoad: true}</script> <script src='dojo/dojo.js'></script> <script> require(["dojo/dom-form","dojo/dom","dojo/on","dojo/json","dojo/request/xhr","dojo/domReady!"],function(domForm,dom,on,JSON,xhr){ var sform = domForm.toObject("myform"); var fdata = JSON.stringify(sform); on(dom.byId("myform"),"submit",function(event){ alert(domForm.toJson("myform")); // Stop the submit event since we want to control form submission. event.stopPropagation(); event.preventDefault(); xhr("http://localhost:8080/Helloweb24/CVSServlet",{ method: "post",query: domForm.toObject("myform"),handleAs: "text" }) .then( function(data){ dojo.byId("response").innerHTML = "Form posted correctly.result is: "+JSON.stringify(data); },function(err){ dojo.byId("response").innerHTML = "Form posted error."+err; }); }); }); </script> </head> <body class="claro"> <b>Simple Form:</b> <br> <blockquote> <form action="CVSServlet" id="myform" name="myform" method="post"> method: <input type="text" name="method" value="xhrpost"></input> Text: <input type="text" name="formInput" value="Some text"></input><br><br> Check
Box: <input type="check
Box" name="check
BoxInput"></input><br><br> <button type="submit" id="submitButton">Send it!</button> </form> </blockquote> <br> <b>Result</b> <div id="response"></div> </body> </html>
原文链接:https://www.f2er.com/dojo/291169.html