Sun River
          Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
          posts - 78,comments - 0,trackbacks - 0

          ---Is there any way that an AJAX object can get back a record set?

          Answer

          You could build an XML document out of your recordset and send that back to the server, say you had a redord set for a "user" with the following details (name, surname, age, email), you could build an xml document like this:

          Code:
          <recordset>
               <user>
                   <name>Byron</name>
                   <surname>Tymvios</surname>
                   <age>25</age>
                   <email>email@address.com</email>
               </user>
               <user>
                   <name>User</name>
                   <surname>Someone</surname>
                   <age>39</age>
                   <email>myAddy@address.com</email>
               </user>
          </recordset>

          You can add as many records as you have in your recordset, then once the client has received it you can use javascript to iterate over the <user>'s in the xml.


          ---Is it possible to set session variables from javascript?
          It's not possible to set any session variables directly from javascript as it is purely a client side technology. You can use AJAX though to asyncronously send a request to a servlet running on the server and then add the data to the session from within the servlet. So you wouldn't be using javascript to do the actual setting of session variables but it would look like it is.
            I've been developing a sliding navigational menu. Here is how I save the state across pages:

          var saveState = true;
          if(saveState)
          {
          // This AJAX call will save the Navigator's state to session.
          // We don't need a callback function because nothing happens
          // once said state is saved.
          var url = "AJAX_Servlet.aspx?function=saveNavigatorState&control=" + id + "&class=" + section.className + "";
          req = new ActiveXObject("Microsoft.XMLHTTP");
          req.open("POST", url, true);
          req.send();
          }
          


          Note that id is set to the Id of the submenu table (which is hidden / shown by other code which sets the className of the table. My stylesheet has css for each class.) earlier in the overal function.
          Here is the codebehind for my AJAX_Servlet.aspx, which could easily be a web service:

          private void Page_Load(object sender, System.EventArgs e)
          {
          if(Request.QueryString["function"] != null)
          {
          if(Request.QueryString["function"] == "saveNavigatorState")
          SaveNavigatorState();
          }
          }
          private void SaveNavigatorState()
          {
          if(Request.QueryString["control"] != null && Request.QueryString["class"] != null)
          {
          string controlID = Request.QueryString["control"].ToString();
          string className = Request.QueryString["class"].ToString();
          Session[controlID] = className;
          }
          }
          


          Then on my navigator codebehind, I just check for session data on load.
          posted on 2007-06-14 06:26 Sun River 閱讀(347) 評論(0)  編輯  收藏 所屬分類: Java Script / Ajax
          主站蜘蛛池模板: 尉氏县| 民和| 铁岭市| 杂多县| 霍林郭勒市| 南岸区| 平南县| 仁化县| 泰宁县| 诸暨市| 林甸县| 大荔县| 师宗县| 临清市| 莱阳市| 通渭县| 漳平市| 香河县| 新干县| 贺兰县| 屯留县| 新宁县| 德江县| 正镶白旗| 师宗县| 桃园市| 北宁市| 平度市| 沂水县| 安顺市| 布拖县| 贺兰县| 台北市| 青海省| 曲靖市| 荆州市| 南昌县| 延庆县| 贵阳市| 张家港市| 太和县|