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 閱讀(355) 評論(0)  編輯  收藏 所屬分類: Java Script / Ajax
          主站蜘蛛池模板: 连州市| 大同县| 杨浦区| 鸡泽县| 台北市| 昌江| 德江县| 颍上县| 罗定市| 乌兰察布市| 云南省| 昌平区| 信丰县| 玉溪市| 拉萨市| 巴楚县| 洱源县| 博乐市| 盐山县| 庄浪县| 天峻县| 图木舒克市| 嘉义县| 那曲县| 全州县| 准格尔旗| 闻喜县| 凭祥市| 南乐县| 慈溪市| 东乡族自治县| 嘉峪关市| 六安市| 佛坪县| 尚志市| 新津县| 仁怀市| 陵川县| 余江县| 资阳市| 谢通门县|