加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dojo post ajax 的方法的使用

发布时间:2020-12-16 21:59:27 所属栏目:百科 来源:网络整理
导读:dojo 是非常强大的前端开发平台,对标签、JS 都有着完善的操作机制,一下举例 dojo 向服务器 post 的实例: 1、数据来自 from 的 dojo post 操作 function sendForm(){ var form = dojo.byId("myform"); dojo.connect(form,"onsubmit",function(event){ // S

dojo 是非常强大的前端开发平台,对标签、JS 都有着完善的操作机制,一下举例 dojo 向服务器 post 的实例:


1、数据来自 from 的 dojo post 操作

function sendForm(){
  var form = dojo.byId("myform");

  dojo.connect(form,"onsubmit",function(event){
    // Stop the submit event since we want to control form submission.
    dojo.stopEvent(event);

    // The parameters to pass to xhrPost,the form,how to handle it,and the callbacks.
    // Note that there isn't a url passed.  xhrPost will extract the url to call from the form's
    //'action' attribute.  You could also leave off the action attribute and set the url of the xhrPost object
    // either should work.
    var xhrArgs = {
      form: dojo.byId("myform"),handleAs: "text",load: function(data){
        dojo.byId("response").innerHTML = "Form posted.";
      },error: function(error){
        // We'll 404 in the demo,but that's okay.  We don't have a 'postIt' service on the
        // docs server.
        dojo.byId("response").innerHTML = "Form posted.";
      }
    }
    // Call the asynchronous xhrPost
    dojo.byId("response").innerHTML = "Form being sent..."
    var deferred = dojo.xhrPost(xhrArgs);
  });
}
dojo.ready(sendForm);

2、数据直接在 js 内构建的 dojo post 操作

function sendText(){
  var button = dijit.byId("submitButton2");

  dojo.connect(button,"onClick",function(event){
    // The parameters to pass to xhrPost,the message,and the url to send it to
    // Also,how to handle the return and callbacks.
    var xhrArgs = {
      url: "postIt",postData: "Some random text",load: function(data){
        dojo.byId("response2").innerHTML = "Message posted.";
      },but that's okay.  We don't have a 'postIt' service on the
        // docs server.
        dojo.byId("response2").innerHTML = "Message posted.";
      }
    }
    dojo.byId("response2").innerHTML = "Message being sent..."
    // Call the asynchronous xhrPost
    var deferred = dojo.xhrPost(xhrArgs);
  });
}
dojo.ready(sendText);


3、数据以 json 方式提交的 dojo post 操作

function sendText(){
  var button = dijit.byId("submitButton2");

  dojo.connect(button,how to handle the return and callbacks.
    var xhrArgs = {
      url: "{{baseUrl}}dojo/dojo.js",postData: dojo.toJson({key1:"value1",key2:{key3:"value2"}}),but that's okay.  We don't have a 'postIt' service on the
        // docs server.
        dojo.byId("response2").innerHTML = "Message posted.";
      }
    }
    dojo.byId("response2").innerHTML = "Message being sent..."
    // Call the asynchronous xhrPost
    var deferred = dojo.xhrPost(xhrArgs);
  });
}
dojo.ready(sendText);

以上参考来自 http://dojotoolkit.org/reference-guide/1.10/dojo/xhrPost.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读