Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. consume webservice using dojo
  2. dojo.query("li").onclick(function(){
  3.         var xhrArgs = {
  4.                 url: "http://192.168.1.65:9080/RAD8JAX-RSWeb/jaxrs/customers",
  5.  
  6.                 handleAs: "json",
  7.                 headers: { "Content-Type": "application/json"},
  8.                 load: function(data) {
  9.                 alert("ok");
  10.                     console.log(data);
  11.                 },
  12.                 error: function(error) {
  13.                     console.log(error);
  14.                 }
  15.             };
  16.              dojo.xhrGet(xhrArgs);
  17.  console.log("message sent ...");
  18. });
  19.        
  20. // Create the store for later use
  21. var store = new dojo.data.ItemFileReadStore({
  22.   contentType: 'application/json'
  23.   ,clearOnClose: true
  24.   ,urlPreventCache: true
  25.   ,url: "http://192.168.1.65:9080/RAD8JAX-RSWeb/jaxrs/customers"
  26. });
  27.        
  28. store.fetch({
  29.   onItem: function(item, request) {
  30.     alert('I fire after each returned json item')
  31.   }
  32.   ,onComplete: function(items, findResult) {
  33.     alert('I fire when the data has loaded completely.');
  34.   }
  35.   ,onError: function(error, request) {
  36.     alert('I fire when an error occurs');
  37.   }
  38. });
  39.        
  40. store.close();