[ 6 posts ]

Daniele

  • Username: dany6883
  • Joined: Tue Aug 02, 2011 5:05 am
  • Posts: 6
  • Offline
  • Profile

DataSource Data Error

Post Posted: Tue Apr 24, 2012 11:18 am
+0-
Hello I'm receiving Data Error with the following code:

Code:
function loadData(){
   
      
       var currentForm = {
            'freeFlowText': document.getElementById("freeFlowInputId").value
        };         
      var yahoo_connect=YAHOO.util.Connect;
      
      
      var responseFailure = function(o) {
      };
      var responseSuccess = function(o) {
         var response=o.responseText;
          // various datatable options
          var dtOptions =
          {
   
             MSG_EMPTY: "No entries",
             MSG_LOADING: "Loading..."
            
          };   
   
         // The label is the text that will be rendered in the table head
         var cols = [
            { key: "hotelName", label: "Hotel Name", sortable: "true", width: 50 },
            { key: "city", label: "City", sortable: "true", width: 250  },
            { key: "state", label: "State/Province", sortable: "true", width: 140  },
            { key: "country",   label: "Country", sortable: "true", width: 180  },
            { key: "n_room", label: "# Rooms", sortable: "true", formatter:"date", width: 120 },
            { key: "n_meeting", label: "# Meeting Rooms", sortable: "true", width: 180  },
            { key: "largest_meeting_room", label: "Largest meeting room (SqFt)", sortable: "true", width: 180  }
         ];   
      
      
         var formObject = document.getElementById('formSearch');
         
         
         var myDataSource = new YAHOO.util.LocalDataSource(JSON.parse(response));
         
         var resultsTable = new YAHOO.widget.DataTable("resultsTable", cols, myDataSource,dtOptions);      
         //myDataSource.sendRequest(JSON.stringify(currentForm),callbackObj);      
         
         myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
         myDataSource.responseSchema = {
           resultsList: "properties",
             fields: [
               {key:"largest_meeting_room"},
               {key:"hotelName"},
               {key:"state"},
               {key:"n_meeting"},
               {key:"n_room"},
               {key:"country"},
               {key:"city"}
              ]
          };
         
         
   
         
         
         // Build requests strings friendly to JDAL
         function requestBuilder (oState, oSelf) {
            // Get states or use defaults
            oState = oState || { pagination: null, sortedBy: null };
            var sort = (oState.sortedBy) ? oState.sortedBy.key : "hotelName";
            var dir = (oState.sortedBy && oState.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc";
         
            // Build custom request
            return  "sort=" + sort +
                  "&dir=" + dir;
         };                  

      };      
            
      var callback = {
        success:responseSuccess,
        failure:responseFailure
      };    
         
      //YAHOO.util.Connect.setForm(formObject);
      yahoo_connect.setDefaultPostHeader(false);
      yahoo_connect.initHeader("Content-Type", "application/json");
      yahoo_connect.initHeader("Accept", "application/json"); 
      yahoo_connect.asyncRequest('POST', 'search', callback, JSON.stringify(currentForm));
      //myDataSource.connMethodPost=true;



the data that I receive from the server for my ajax call is

{"properties":[{"largest_meeting_room":700,"hotelName":"DistributedCode","state":"MS","n_meeting":222,"n_room":100,"country":"US","city":"mon univers impitoyable"}]}

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: DataSource Data Error

Post Posted: Tue Apr 24, 2012 12:33 pm
+0-
The DataTable uses the DataSource as soon as it is created. You are setting the responseType and responseSchema after it has already been used.

Anyway, I'm not sure why are you handling the communication yourself and then using the DataSource since DataSource is quite capable of doing it all.

Daniele

  • Username: dany6883
  • Joined: Tue Aug 02, 2011 5:05 am
  • Posts: 6
  • Offline
  • Profile
Tags:

Re: DataSource Data Error

Post Posted: Tue Apr 24, 2012 1:22 pm
+0-
Hello thank you for your response.
I'm maaging by my self the ajax request because if I create a new DataSource("search"), is going to send a GET request to the URL: search while I should need to do a POST request and I didn't find a way to set the information about the http method POST if not in the Connect.util.asyncRequest...

thank you for your informations

Daniele Ippoliti

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: DataSource Data Error

Post Posted: Tue Apr 24, 2012 8:59 pm
+0-
http://developer.yahoo.com/yui/docs/YAH ... MethodPost

Daniele

  • Username: dany6883
  • Joined: Tue Aug 02, 2011 5:05 am
  • Posts: 6
  • Offline
  • Profile

Re: DataSource Data Error

Post Posted: Tue Apr 24, 2012 10:36 pm
+0-
ok and how can I pass in this way the body of the POST?

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: DataSource Data Error

Post Posted: Wed Apr 25, 2012 4:44 am
+0-
Whatever goes into initialRequest gets send in the POST body.

See:

http://developer.yahoo.com/yui/examples ... stxml.html

Whether you use XML or not, the POST part is still valid.
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum