php的無重新整理實現方法

來源:互聯網
上載者:User

標籤:doctype   img   har   狀態代碼   圖片   frame   value   pre   使用者名稱   

方法一:

我們通過http的204狀態代碼,頁面不跳轉。1.html代碼如下:
<!DOCTYPE HTML><html lang="zh-CN"><head>    <meta charset="UTF-8">    <title></title></head><body>    <a href="./add.php">投票</a></body></html>
add.php代碼如下:
<?php$num = file_get_contents(‘./num.txt‘);$num = intval($num) + 1;file_put_contents(‘./num.txt‘, $num);header(‘HTTP/1.1 204 No Content‘);
方法二:利用圖片載入的特性,來完成請求。
<!DOCTYPE HTML><html lang="zh-CN"><head>    <meta charset="UTF-8">    <title></title></head><body>    <input type="button" value="投票" id="addBtn" />    <div id="request"></div></body><script type="">    var addBtn = document.getElementById("addBtn");    addBtn.onclick = function() {        //建立img標籤        var img = document.createElement("img");        //設定標籤src屬性        img.setAttribute("src", "add.php");        document.createElement("request").appendChild(img);    };</script></html>
方法三:利用css,javascript的載入特性,完成請求,原理與img載入一樣。 方法四:利用iframe的特性2.html代碼如下:
<!DOCTYPE HTML><html lang="zh-CN"><head>    <meta charset="UTF-8">    <title></title></head><body>    <form action="ret.php" method="post" target="request">        使用者名稱:<input type="text" name="uname" value="" />        密碼:<input type="password" name="upwd" value="" />        <input type="submit" name="submit" value="提交" />    </form>    <iframe width="0" height="0" frameborder="0" name="request"></iframe>    <div id="result"></div></body></html>
ret.php代碼如下:
<?php$uname = !empty($_POST[‘uname‘]) ? $_POST[‘uname‘] : ‘‘;$upwd = !empty($_POST[‘upwd‘]) ? $_POST[‘upwd‘] : ‘‘;if($uname == ‘admin‘ && $upwd == ‘123456‘) {    echo "<script>parent.document.getElementById(‘result‘).innerHTML=‘OK‘;</script>";} else {    echo "<script>parent.document.getElementById(‘result‘).innerHTML=‘NO‘;</script>";}
我們通過設定form提交的target到iframe,使表單無跳轉。 ajax能實現檔案上傳嗎?分析,檔案上傳,是需要用戶端把檔案內容發送到伺服器,也就是XHR對象在POST資料時,把檔案內容也發送給伺服器。也就是XHR對象能夠擷取你要上傳的檔案內容,但是出於安全的考慮,JS是無法擷取本地檔案內容的。 ajax外掛程式是如何?檔案上傳的?
1、iframe2、flash實現,如swfupload3、html5 (添加了檔案讀取api,使ajax上傳檔案成為可能。)

 

php的無重新整理實現方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.