AJAX-prototype.js实现Ajax
生活随笔
收集整理的這篇文章主要介紹了
AJAX-prototype.js实现Ajax
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼分兩部分
1.用一個簡單服務器腳本rand.php模擬不斷變化的股票價格:
2.新建一個prototype-test.html文件,
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Stock</title><script src="prototype.js"></script><script>function checkprice() {var myAjax = new Ajax.PeriodicalUpdater('price','rand.php',{method:'post',frequency:3.0,decay:1});}window.onload = checkprice;</script> </head> <body> <h2>Stock Reader</h2> <p>Current Stock Price:</p> <div id="price"></div></body> </html>這個界面很簡單,一個標題一行文字,還有顯示股票價格的div,
圖中紅圈位置的數據會隨時變化.
prototype.js的一些類封裝的代碼可以發送服務器請求,監視請求的過程,處理返回的數據.
Ajax.Request
var myAjax = new Ajax.Request(url,{method:’post’,parameters:mydata,onComplete:responseFunction});
Ajax.Updater
var myAjax = new Ajax.Updater(elementID,url,options);
Ajax.PeriodicalUpdater
var myAjax = new Ajax.PeriodicalUpdater(‘id’,’url’,{method:’post’,frequency:3.0,decay:1});
這個是本案例使用的,比Ajax.Updater多了兩個參數frequency,decay
總結
以上是生活随笔為你收集整理的AJAX-prototype.js实现Ajax的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AJAX-简单示例
- 下一篇: Python Flask-表单提交方式