javascript post mothed

          Hi I am currently re-developing a web based front end for an estate agent to manage their propertys. I have decided to use a Microsoft.XMLHTTP object to communicate between the client and server. My problem is got to do with sending a file with this. The client is composed of the usual GUI components which the data can be easily retrieved from for sending to the server but it also contains a file element for selecting a picture of the property to be uploaded. How do I get the data from this so that it can be uploaded to the server using the Microsoft.XMLHTTP object. I have found a bit of code on the net but it is no use to me because it would involve changing the security in "Internet Options" which I have no control over.

          <HTML>
          <HEAD><TITLE>File Send</TITLE></HEAD>
          <BODY>
             
          <INPUT id=btn_send name="btn_send" type=button value="FILE SEND">
             
          <DIV id=div_message>Ready</DIV>
          </BODY>
          </HTML>

          <SCRIPT LANGUAGE=JavaScript>

          // files upload function
          function btn_send.onclick()
          {
             
          // create ADO-stream Object
             var ado_stream = new ActiveXObject("ADODB.Stream");

             
          // create XML document with default header and primary node
             var xml_dom = new ActiveXObject("MSXML2.DOMDocument");
             xml_dom.loadXML('
          <?xml version="1.0" ?> <root/>');
             
          // specify namespaces datatypes
             xml_dom.documentElement.setAttribute("xmlns:dt""urn:schemas-microsoft-com:datatypes");

             
          // create a new node and set binary content
             var l_node1 = xml_dom.createElement("file1");
             l_node1.dataType 
          = "bin.base64";
             
          // open stream object and read source file
             ado_stream.Type = 1;  // 1=adTypeBinary 
             ado_stream.Open(); 
             ado_stream.LoadFromFile(
          "c:\\sold.gif");
             
          // store file content into XML node
             l_node1.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
             ado_stream.Close();
             xml_dom.documentElement.appendChild(l_node1);

             
          // we can create more XML nodes for multiple file upload

             
          // send XML documento to Web server
             var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
             xmlhttp.open(
          "POST","http://www.google.com",false);
             xmlhttp.send(xml_dom);
             
          // show server message in message-area
             div_message.innerHTML = xmlhttp.ResponseText;
          }
          </SCRIPT>

          posted on 2007-07-17 09:47 leoli 閱讀(961) 評(píng)論(0)  編輯  收藏 所屬分類: javascript


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案(17)

          文章分類(86)

          收藏夾(3)

          flex blog

          good site

          java blog

          my friend

          tools

          抓蝦

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 呼和浩特市| 上蔡县| 广昌县| 孝昌县| 龙川县| 响水县| 阿克陶县| 巴里| 隆子县| 勃利县| 岳阳市| 凤庆县| 渭南市| 阿拉尔市| 扶余县| 吉林市| 临沭县| 小金县| 项城市| 大田县| 遂溪县| 梧州市| 莆田市| 嘉兴市| 富锦市| 澄江县| 长武县| 南昌县| 女性| 曲松县| 安远县| 汉中市| 滕州市| 吴忠市| 兰西县| 广汉市| 南开区| 文成县| 潮安县| 林周县| 多伦县|