JavaScript HttpRequest JavaScript
<HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <TITLE>test</TITLE> <script src="prototype.js"></script> <script> function test1() { new Ajax.Request('test.txt',{ onComplete : function (request) { $('idtest1').innerHTML = request.responseText; } }); } </script> </HEAD> <BODY> <div id="idtest1"> </div> <input type="button" value=Test1 onclick="test1();"><br> </BODY> </HTML>
JavaScript http://clouder.jp/yoshiki/mt/archives/000437.html
http://www.getahead.ltd.uk/dwr/
c:\dwrsample\dwr.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis" /> <title>DWR</title> <script type='text/javascript' src='dwr/interface/Testdwr.js'></script> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script type='text/javascript'> <!-- function searchAddress () { var zipcode = DWRUtil.getValue("zipcode"); if (zipcode.length == 7) { Testdwr.getZipdata(result,zipcode); } } function result(data) { DWRUtil.setValues(data); } // --> </script> </head> <body> </body> </html>
c:\dwrsample\WEB-INF\src\com\hidekazu\dwr\Testdwr.java
package com.hidekazu.dwr; import java.util.HashMap; public class Testdwr { public HashMap getZipdata(String data) { HashMap map = new HashMap(); return map; } }
c:\dwrsample\WEB-INF\dwr.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd"> <dwr> <allow> <create creator="new" javascript="Testdwr" scope="session"> <param name="class" value="com.hidekazu.dwr.Testdwr"/> </create> </allow> </dwr>
c:\dwrsample\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app id="dwr"> <display-name>DWR (Direct Web Remoting)</display-name> <description>A demo of how to call Java on the server directly from Javascript on the client</description> <servlet> <servlet-name>dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <description>Direct Web Remoter Servlet</description> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app>
http://localhost:8080/dwrsample/dwr.html JAVA PRESS Vol.44
c:\dwrsample\WEB-INF\src\com\hidekazu\dwr\Testdwr.java
package com.hidekazu.dwr; import java.util.HashMap; import javax.servlet.http.HttpSession; import uk.ltd.getahead.dwr.ExecutionContext; public class Testdwr { public HashMap getZipdata(String data) { //ServletContext context = ExecutionContext.get().getServletContext(); HttpSession session = ExecutionContext.get().getHttpServletRequest().getSession(); if (session.getAttribute("test2") == null) { session.setAttribute("test2",data); } HashMap map = new HashMap(); map.put("test2",session.getAttribute("test2")); return map; } }
c:\dwrsample\dwr.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis" /> <title>DWR</title> <script type='text/javascript' src='dwr/interface/Testdwr.js'></script> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script type='text/javascript'> <!-- var resData; function searchAddress () { var zipcode = DWRUtil.getValue("zipcode"); if (zipcode.length == 7) { Testdwr.getZipdata(result,zipcode); } } function result(data) { DWRUtil.setValues(data); resData = DWRUtil.toDescriptiveString(data, 2); //DWRUtil.setValue("test2","aa"); } function btnKakunin() { alert(resData); } // --> </script> </head> <body> </body>
http://www.javaworld.jp/enterprise/-/20862.html
http://hidekazu.dhs1.sst.ne.jp/xoops/html/
{"data": [ ], "count":"2" };
test1.php
<script type="text/javascript"><!-- function getData() { new Ajax.Request('test.php',{ method: 'get', onSuccess:getResponse }); } function getResponse(req) { eval("var dataObject = " + req.responseText); $('target').innerHTML = dataObject.data[0].test1; var target2data = ""; for(var intfor=0; intfor < dataObject.data.length; intfor++) { target2data += dataObject.data[intfor].test1 + dataObject.data[intfor].test2 + "<br>"; } $('target2').innerHTML = target2data; $('target3').innerHTML = dataObject.count; var tbody = $('result'); for(var intfor=tbody.rows.length-1; intfor >=0 ; intfor--) { var tr=tbody.deleteRow(intfor); } for(var intfor=0; intfor < dataObject.data.length; intfor++) { var tr=tbody.insertRow(intfor); tr.insertCell(0).innerHTML = dataObject.data[intfor].test1; tr.insertCell(1).innerHTML = dataObject.data[intfor].test2; } } //--> </script> <table> <thead> <tr> <th> test1 </th> <th> test2 </th> </tr> </thead> <tbody id="result"> </tbody> </table>
test.php
<?php echo '{"data":'; echo '['; $intCnt = 0; $sql = "SELECT * FROM ". $xoopsDB->prefix("users"); $result = $xoopsDB->query($sql); while ($myrow = $xoopsDB->fetchArray($result)) { if ($intCnt > 0) { echo ','; } $intCnt++; $uname = $myrow["uname"]; $name = mb_convert_encoding($myrow["name"], 'UTF-8',mb_internal_encoding()); echo '{"test1":"'.$uname.'", "test2":"'.$name.'"}'; } echo ']'; echo ',"count":"'.$intCnt.'"'; echo '};'; ?>
HttpRequest http://at-shima.cocolog-nifty.com/blog/2007/03/javascriptjavas_79bb.html
<script src="prototype.js" type="text/javascript"></script>
http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html http://www.xml.com/2005/12/21/examples/jsr_class.zip NscriptRequest?
<html> <script src="prototype.js" type="text/javascript"></script> <script src="jsr_class.js" type="text/javascript"></script> <script type="text/javascript"> var oJsr; function getData() { var attr = 'zip=10'; oJsr = new JSONscriptRequest('http://www.hoge.com/hoge.php?'+attr+'&callback=hundler'); oJsr.buildScriptTag(); oJsr.addScriptTag(); } function hundler(dataobj) { if (dataobj.count > 0) { $('id1').value = dataobj.data[0].id1; } oJsr.removeScriptTag(); } </script> <body> <input name="id1" type="text" id="id12"/> </body> </html>
hundler({data:[{id1:"05", id2:"10"}],count:"1"});
http://www.google.com/apis/maps/
http://hidekazu.dhs1.sst.ne.jp/googlemap/index.htm
<scrip t src="http://maps.google.com/maps?file=api&v=1&key=hogehoge" type="text/javascript"></script>
<scrip t src="http://maps.google.com/maps?file=api&v=1&key=hogehoge" type="text/javascript" charset="utf-8"></script>