Ajax示例

AJAX基本示例


<script>
//set the variables.
function getArticle(id) {
    var link = "/getNews.asp";
    xmlhttpPost(link, id);
} 
//Make the actual connection.
function xmlhttpPost(strURL, id) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) { //ready state 4 means its complete.
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring(id));
} 
//set the query string to be sent
function getquerystring(id) {
    qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
    return qstr;
} 
//put the data on the page.
function updatepage(str) {
    document.getElementById("data").innerHTML = str;
}
</script>
<select onchange="getArticle(this.value);">
<option value="1">Train hits car</option>
<option value="2">Airplane Crashes</option>
<option value="3">Mental Health</option>
</select>
<div id="data"></div> 

现在获取getNews.asp ---不是全部功能的代码,而是一个示例


<%
news_id = request("id")
strSQL = "select * from news where news_id = " & new_id
rs.open strSQL, connection, 1, 1
if not rs.eof then
response.write rs("story")
end if
%> 

From: https://bytes.com/topic/javascript/insights/666300-ajax-example

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值