Ms7 Search
Google 搜尋 翻譯
calendar
« 九月 2024 »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
近期文章
文章分類
網站連結
Syndicate

« | »

ajax 的學習

2007-11-08 @ 11:24 in PHP, JavaScript, Sql

這幾天都在研究 ajax 的用法,AJAX全稱為「Asynchronous JavaScript and XML」(非同步JavaScript和XML),是指一種創建交互式網頁應用的網頁開發技術,最好的地方是向server提出需求,只要更新部分網頁內容,不用全部更新,並且server在處理時,client也可以動作,server處理完,自動更新,client不用等待,所以叫非同步,它必需有 dom,javascript,xml的基礎,對我來講有點難,看了幾篇教學,只大約有個概念,等那天故意用它寫個網頁程式試試...

下面好像是從 ibm 網站看來的例題,再加上自己的一點備註 

<script language="javascript" type="text/javascript">
var request = false;
try
    {   request = new XMLHttpRequest(); }
catch(trymicrosoft)
    {
    try
        {   request = new ActiveXObject("Msxml2.XMLHTTP");  }
    catch(othermicrosoft)
        {
        try
            {   request = new ActiveXObject("Microsoft.XMLHTTP");   }
        catch(failed)
            {   request = false;    }
        }
    }
if(!request)
    alert("Error initializing XMLHttpRequest!");

function getCustomerInfo()
    {
// Get 方式
    var phone = document.getElementById("phone").value;
    var url = "lookupCustomer.php?phone=" + escape(phone);
    request.open("GET",url,true);
    request.onreadystatechange = updatePage;
    request.send(null);
/* Post 方式
    var phone = document.getElementById("phone").value;
    var url = "lookupCustomer.php";
    request.onreadystatechange = updatePage;
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.send("phone="+phone+"&item="+itemCode);
*/
    }

function updatePage()
    {
    if(request.readyState == 4)
        {
        if(request.status == 200)
            {
            var response = request.responseText.split("|");  //server必須送回  "字串 | 字串 | ..."格式 ,如果是 php 用 echo 送回
            document.getElementById("order").value = response[0];
            document.getElementById("address").innerHTML = response[1].replace(/\n/g,"");
            }
        else
            {   alert("Error: status code is " + request.status);   }
        }
    }
</script>

<body>
    <p><img src="breakneck-logo_4c.gif" alt="Break Neck Pizza" /></p>
    <form action="POST">
    <p>Enter your phone number:

    <input type="text" size="14" name="phone" id="phone"
          onChange="getCustomerInfo();" />

    </p>
    <p>Your order will be delivered to:</p>
    <div id="address" ></div>
    <p>Type your order in here:</p>
    <p><textarea name="order" rows="6" cols="50" id="order"></textarea></p>
    <p><input type="submit" value="Order Pizza" id="submit" /></p>
    </form>
 </body>

迴響

ajax 的學習 | 豬窩

Males will get the female of their choice without difficulty through free dating sites.
There are several Americans who believe Inter racial relationships needs to be banned
since it destroys the cultures of two races and also brings
problem with their siblings. Founded by the clinical psychologist that has extensive experience and understand human behavior and
social dynamics, e - Harmony features a patented
Compatibility Matching system that is effective in matching compatible singles.

作者 love @ 10:55, 2019-04-06

ajax 的學習 | 豬窩

They are not new txt messaging acronyms - they're actually acronyms for gaming which article is going
to tell you about some of the more prevalent forms.
One of the most popular sites that the teens may choose to visit is liven up the
portals that incorporate games for teens that they may
enjoy. There are a lot of people who use these games as being a stress buster by themselves and also
the others find then fun after a long day of work.

作者 http://Ren.Megam.info/ @ 02:48, 2019-04-12

ajax 的學習 | 豬窩

They also have scratch games, they will call Skratch card games, given that they have altered these games to include that
skill and have a bonus rounds. One of the most widely used sites that your teens may
want to visit is liven up the portals that contain games for teens that they may enjoy.
Like recounted before, this is the spot where sports spread
betting will disclose results profitable ones I mean.

作者 http://war.Leadin.site/ @ 11:11, 2019-04-13

ajax 的學習 | 豬窩

They also have scratch card games, they will call Skratch games,
since they have altered these games to incorporate a degree of
skill and have a bonus rounds. Let's start our discussion with where we can easily find such videos.
On the other hand, Queensland has additionally shown a massive length
of spending in previous years.

作者 Asprop.cl @ 17:02, 2019-04-14

ajax 的學習 | 豬窩

Online dating can be the perfect solution in case you want to fulfill singles in your area.
These scammers usually just have one picture in their profile, thus it will be the norm
for many experienced individuals who date online to feel that one picture profiles don't
show the true person. The choice is perhaps all yours, does
one want to share your existing email, your numbers, your address and even your surname.

作者 fitourindonesia.com @ 16:37, 2019-04-17
發表迴響
 authimage