日期:2014-05-16  浏览次数:20827 次

Learning Dojo -- 5. Remote Scripting (AJAX)

1. Remote Scripting is not just AJAX . There are 3 ways.
   a.XHR(AJAX) -> Same-Origin Limited
   b.iframe    -> Same-Orignin Limited; It can post a file.
   c.Loading a script element ->  Not limited to Same-Origin Policy

2. XHR with dojo
     a. Example
     dojo.xhrGet({
    url: "demo/id2",
    handleAs: "json",
    handle: handler4
  });

     b. Some notes
        i.handleAs: text/json/xml
       ii.preventCache
      iii.It can also cooperate with forms

3.Loading a script element
    a.dojo supports this with JSONP
    b.API: dojo.io.get()... The syntax is almost the same with XHR


4.iframe
    a.How does it work?
         i.A hidden iframe is used
        ii.The handler is triggerd for "onload" event of this iframe
       iii.it always returns HTML content
    b.How does dojo help with this?
        I don't care for now