Request is the basic XHR request class in MooTools : Ajax « Mootools « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Mootools » Ajax 
Request is the basic XHR request class in MooTools
 

<!--
MooTools is released under the Open Source MIT license, 
which gives you the possibility to use it and modify 
it in every circumstance. 
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
#result {
  width: 500px;
  padding: 10px;
  background-color: #F9F9F9;
  border-right: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
}  
  
  </style>
  <script type="text/javascript" src="mootools.js"></script>
  <script type="text/javascript">
window.addEvent('domready', function(){
  // You can skip the following line. We need it to make sure demos
  // are runnable on MooTools demos web page.
  var demo_path = window.demo_path || '';
  // --

  //We can use one Request object many times.
  var req = new Request({

    url: demo_path + 'data.txt',

    onSuccess: function(txt){
      $('result').set('text', txt);
    },

    // Our request will most likely succeed, but just in case, we'll add an
    // onFailure method which will let the user know what happened.
    onFailure: function(){
      $('result').set('text', 'The request failed.');
    }

  });

  $('makeRequest').addEvent('click', function(){
    req.send();
  });

  $('failedRequest').addEvent('click', function(e){
    //We can pass new options for our Request object to the send method.
    req.send({url:'/assets/not_here.txt'});
  });

});
  
  </script>
  <title>Request Demo</title>
</head>
<body>
  <h1>Request</h1>
  <h2>Introduction</h2>
  <p>
    Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTML and Request.JSON.
  </p>
  <p>
    <a href="#" id="makeRequest" title="Make Request">Make Request</a> | <a href="#" id="failedRequest">This Request Will Fail</a>
  </p>
  <h2>Result</h2>
  <div id="result">Waiting for the request to happen.</div>
</body>
</html>

   
     
  
Related examples in the same category
1.Request HTML
2.Request JSON
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.