ajax和php,AJAX与PHP(一)

// executed automatically when a message is received from the server

function handleServerResponse()

{

// move forward only if the transaction has completed

if (xmlHttp.readyState == 4)

{

// status of 200 indicates the transaction completed successfully

if (xmlHttp.status == 200)

{

// extract the XML retrieved from the server

xmlResponse = xmlHttp.responseXML;

// obtain the document element (the root element) of the XML structure

xmlDocumentElement = xmlResponse.documentElement;

// get the text message, which is in the first child of

// the the document element

helloMessage = xmlDocumentElement.firstChild.data;

// update the client display using the data received from the server

document.getElementById("divMessage").innerHTML = '' + helloMessage + '';

// restart sequence

setTimeout('process()', 1000);

}

// a HTTP status different than 200 signals an error

else

{

alert("There was a problem accessing the server: " + xmlHttp.statusText);

}

}

}PHP文件:<?php

// we'll generate XML output

header('Content-Type: text/xml');

// generate XML header

echo '<?xml version="1.0" encoding="UTF-8" standal?>';

// create the element

echo '';

// retrieve the user name

$name = $_GET['name'];

// generate output depending on the user name received from client

$userNames = array('CRISTIAN', 'BOGDAN', 'FILIP', 'MIHAI', 'YODA');

if (in_array(strtoupper($name), $userNames))

echo 'Hello, master ' . htmlentities($name) . '!';

else if (trim($name) == '')

echo 'Stranger, please tell me your name!';

else

echo htmlentities($name) . ', I don\'t know you!';

// close the element

echo '';

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值