Changes between Version 8 and Version 9 of AJAX/Dojo/RefactoredFormSubmit


Ignore:
Timestamp:
Feb 11, 2007, 10:41:41 AM (17 years ago)
Author:
erob@…
Comment:

added core js block

Legend:

Unmodified
Added
Removed
Modified
  • AJAX/Dojo/RefactoredFormSubmit

    v8 v9  
    6565from the list of required modules above, so we wont load the already compiled
    6666Dojo modules twice.   
     67
     68=== Form validating w/ dojo.io.bind ===
    6769 
    6870Let's complete our application by writing down the core JS file,
     
    7072
    7173{{{
    72 ...
     74function validate() {
     75    var fNode = dojo.byId('xForm');
     76    var fParms = dojo.io.encodeForm(fNode);
     77    var bindArgs = {
     78        url: ".",
     79        mimetype: 'text/json',
     80        method: "post",
     81        preventCache: true,
     82        transport: "XMLHTTPTransport",
     83        postContent: fParms,
     84        error: function(type, error){
     85               // handle error here
     86               // var errorBox = dojo.byId('errorMsg');
     87               // errorBox.childNodes[0].nodeValue = error;
     88               alert(error.message);
     89               return false;
     90        },
     91        load: function(type, data, evt){
     92              // handle successful response here
     93              if(type == 'load'){
     94                var myDiv = dojo.byId('errorBox1')
     95                // XXX not sure what to do if the data is JSON or
     96                // something else..
     97                var json = dojo.json.evalJson(data)
     98                if(json){
     99                   errStr = ''
     100                   for(x in json){
     101                     errStr += x + ': ' + json[x] + '<br />'
     102                   }
     103                   myDiv.innerHTML = errStr
     104                }else{
     105                   myDiv.innerHTML = "hello, world!"
     106              }}
     107       }}
     108       var xmlhttp = dojo.io.bind(bindArgs)
     109       return xmlhttp
     110}
    73111}}}
     112
     113Notice the removal of ''formNode'' for ''postContent'', and the
     114use of ''dojo.io.encodeForm'' to parse/encode the form data in
     115a proper format.
    74116
    75117=== Limitations/Bugs ===
Back to Top