⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liveconnectexample2.htm

📁 这是javascript高级程序设计的源码
💻 HTM
字号:
<html>
    <head>
        <title>LiveConnect Example</title>
        <script type="text/javascript">
        
                function httpPost(sURL, sParams) {
                                       
                    var oURL = new java.net.URL(sURL);
                    var oConnection = oURL.openConnection();
                
                    oConnection.setDoInput(true);
                    oConnection.setDoOutput(true);
                    oConnection.setUseCaches(false);                
                    oConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");                
                
                    var oOutput = new java.io.DataOutputStream(oConnection.getOutputStream());
                    oOutput.writeBytes(sParams);
                    oOutput.flush();
                    oOutput.close();
                
                    var sLine = "", sResponseText = "";
                
                    var oInput = new java.io.DataInputStream(oConnection.getInputStream());                                
                    sLine = oInput.readLine();
                    
                    while (sLine != null){                                
                        sResponseText += sLine + "\n";
                        sLine = oInput.readLine();
                    }
                                                  
                    oInput.close();                                  
                
                    return sResponseText;                         
                }
                
                function addPostParam(sParams, sParamName, sParamValue) {
                    if (sParams.length > 0) {
                        sParams += "&";
                    }
                    return sParams + encodeURIComponent(sParamName) + "=" 
                                   + encodeURIComponent(sParamValue);
                }
                
                function getServerInfo() {
                    var sParams = "";
                    sParams = addPostParam(sParams, "name", "Nicholas");
                    sParams = addPostParam(sParams, "book", "Professional JavaScript");
                    var sResponseText = httpPost("http://localhost/reflectpost.php", sParams);
                        
                    alert("Response text is: " + sResponseText);
                }

        </script>
    </head>
    <body>
        <p>Click the button to make a call to the server using LiveConnect.
        This example will only work when run in a Web server environment. You'll need
        to change the URL <code>http://localhost/reflectpost.php</code> to point to a valid
        file on the server. If this works, you should see the same values that
        were POSTed to the URL.</p>
        <input type="button" onclick="getServerInfo()" value="Get Server info" />
    </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -