| Page 1 of 1 | [ 6 posts ] |
|
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"}]} |
|
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. |
|
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 |
|
ok and how can I pass in this way the body of the POST?
|
|
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. |
| Page 1 of 1 | [ 6 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group