当前位置: 首页 > 图文教程 > 网络编程 > Javascript > dojo 之基础篇(三)之向服务器发送数据

Javascript
JQuery的ajax基础上的超强GridView展示
js表格分页实现代码
下载站控制介绍字数显示的脚本 显示全部 隐藏介绍等功能
Tab页界面,用jQuery及Ajax技术实现
用jQuery技术实现Tab页界面之二
通过JS 获取Mouse Position(鼠标坐标)的代码
javascript 必知必会之closure
jquery ajax 登录验证实现代码
jQuery 使用手册(一)
jQuery 使用手册(二)
jQuery 使用手册(三)
jQuery 使用手册(五)
用Javascript 获取页面元素的位置的代码
网页自动跳转代码收集
JS 连锁泡泡 v1.1
javascript的onchange事件与jQuery的change()方法比较
jquery 模式对话框终极版实现代码
javascript 页面划词搜索JS
javascript String split方法误操作
一个JS小玩意 几个属性相加不能超过一个特定值.

Javascript 中的 dojo 之基础篇(三)之向服务器发送数据


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 208 ::
收藏到网摘: n/a

向服务器发送数据有get和post两种.
首先,要将body中的html代码替换为
 <button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
请输入名称: <input type="text" id="name">
不输入数据,怎么提交数据呢.
  1. get
    我们只要将基础篇(二)中的:
     function helloPressed()
    {
    dojo.io.bind({
    url: 'response.txt',
    handler: helloCallback
    });
    }
    替换为:
     function helloPressed()
    {
    dojo.io.bind({
    url: 'HelloWorldResponseGET.jsp',
    handler: helloCallback,
    content: {name: dojo.byId('name').value }
    });
    }
    即可.其中的url不用说也明白了吧.是相对路径.也就是说在HelloWorld.html的当前目录
    下应该有一个 HelloWorldResponseGET.jsp 文件. handler还是一样,处理返回的数据,
    如果有的话.
    content即为要发送的数据. 其中名称为name,name的值为你所输入的值.
    这样,我们可以在jsp中写入简单的代码来获得这个值,以下为jsp中的代码
    <%
    /*
    ' HelloWorldResponseGET.jsp
    ' --------
    '
    ' 打印name的值.
    '
    */
    response.setContentType("text/plain");
    %>
    Hello <%= request.getParameter("name") %> ,欢迎来到dojo世界!
  2. Post
    这种方法即为在form表单提交提交数据.
    相应的html代码为:
     <button dojoType="Button" widgetId="helloButton">Hello World!</button>
    <br>
    <form id="myForm" method="POST">
    请输入名称: <input type="text" name="name">
    </form>
    dojo代码为:
     function helloPressed()
    {
    dojo.io.bind({
    url: 'HelloWorldResponsePOST.jsp',
    handler: helloCallback,
    formNode: dojo.byId('myForm')
    });
    }
    这里将content属性变为了formNode属性.
    jsp的代码不变.
到此,dojo的基础篇告一段落. 这些内容来自dojo的官方网站. 更详细的内容请参考官网.
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld