<form name="myform"> 姓名:<input type="text" id="name"></input> <input type="button" onClick="callRemote();" value="確定"></input> </form>
01 function callRemote() { 02 sUrl = "/jlu/servlet/HelloWorld?name=" + 03 encodeURIComponent(document.getElementById('name').value); 04 dojo.xhrGet({ 05 url: sUrl, 06 load: function(data) { 07 alert(data); 08 }, 09 error: function(data) { 11 alert('Server error'); 12 } 13 }); 14 }
<SCRIPT TYPE="text/javascript" SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.2.3/dojo/dojo.xd.js" djConfig="parseOnLoad: true"></SCRIPT>
01 dojo.xhrGet({ 02 url: sUrl, 03 load: function(data) { 04 alert(data); 05 }, 06 error: function(data) { 07 alert('Server error'); 08 } 09 });
// 方法一(常用的方式) function helloWorld() { alert("Hello World"); } // 方法二(匿名方法) var helloWorld = function() { alert("Hello World"); };
var obj = {name: "Java, hours: 50};
var obj = {name: "Java, hours: 50, toString: function() { alert(this.name + " 工作了 " + this.hours + " 小時"); } }; obj.toString();
<SCRIPT TYPE="text/javascript" SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.2.3/dojo/dojo.xd.js" <script type="text/javascript"> var transaction; var sUrl; var callback = { success: function(o) { alert(o.responseText); }, failure: function(o) { alert("錯誤:無法取得回應"); } }; function callRemote() { sUrl = "/jlu/servlet/HelloWorld?name=" + encodeURIComponent(document.getElementById('name').value); dojo.xhrGet({ url: sUrl, load: function(data) { alert(data); }, error: function(data) { alert('Server error'); } }); } </script> </head>