PHP+AjaxʵÏÖ·ÖÒ³¼¼Êõ£º
»ùÓÚphpºÍajaxµÄ·ÖÒ³¼¼Êõ´úÂ룬ÏÂÃæÓÐÁ½¸öphpÎļþ£¬Ò»¸öÊÇsn_inq.php£¬ÁíÒ»¸öÊÇsn_show.php£¬Ç°Ò»¸öphpÎļþµ÷ÓúóÒ»¸öphpÎļþ£¬ÊµÏÖajax·ÖÒ³£¬ÔËÐÐsn_inq¼´¿ÉʵÏÖЧ¹û£¬²»¹ýµÃÐÞ¸ÄÊý¾Ý¿âŶ¡£¾ßÌå´úÂëÈçÏ£ººìÉ«±ê×¢µÄµØ·½ÒªÌرð×¢ÒâÐÞ¸ÄŶ£¡
ÎÒµÄÊý¾Ý¿âÃûÊÇinv£¬±íÃûÊÇsn£¬×Ö¶ÎÓУºsn_id,sn_plant,sn_sales,sn_act,sn_type,sn_sts.....
1.sn_inq.php
//getFormValue ÓÃÓÚ»ñÈ¡±íµ¥ÖÐËùÓÐÊäÈë¿Ø¼þµÄÖµ£¬²¢½«ÊäÈëÖµ×é³ÉÒ»¸ö×Ö·û´®´«µ½·þÎñÆ÷¡£
<script type="text/javascript">
function getFormValue(form){
var str='';
var ft,fv;
for (var i=0; i<form.elements.length; i++){
fv = form.elements[i];
ft = fv.type.toLowerCase();
switch(ft){
case 'select-one':
str+=fv.name+'='+escape(fv.value)+'&';
break;
case 'radio':
if (fv.checked){
str+=fv.name+'='+escape(fv.value)+'&';
}
break;
case 'checkbox':
if (fv.checked){
str+=fv.name+'='+escape(fv.value)+'&';
}
break;
case 'text':
str+=fv.name+'='+escape(fv.value)+'&';
break;
case 'password':
str+=fv.name+'='+escape(fv.value)+'&';
break;
case 'hidden':
str+=fv.name+'='+escape(fv.value)+'&';
break;
case 'textarea':
str+=fv.name+'='+escape(fv.value)+'&';
break;
default:
break;
}
}
return str.split(/\s/).join('')
}
//showcomment(page) ÓÃÓÚÏÔʾ·ÖÒ³Êý¾Ý£¬±»²éѯ°´Å¥onclick ʼþµ÷Ó㬠urlΪºǫ́´¦ÀíÊý¾Ý²¢Êä³öXML¸ñʽÊý¾ÝµÄÎļþurl¡£
function showcomment(page) {
var x = new Ajax('statusid', 'XML');
url = 'sn_show.php?page='+page+'&'+getFormValue(document.form1);
x.get(url , function(s) {
if(s.lastChild){
getbyid("show").innerHTML = "Loading……";
getbyid("show").innerHTML = s.lastChild.firstChild.nodeValue;
removeLoading(document.getElementById("show"));
}
else{
document.form1.submit();
}
});
}
//displayLoadingÓÃÓÚÏÔʾLoading£¬ÌáʾÓû§µÈ´ý
function displayLoading(element) {
var image = document.createElement("img");
image.setAttribute("src","progressbar.gif");
image.setAttribute("title","loading...");
var text = document.createTextNode("loading……");
element.appendChild(image);
element.appendChild(text);
}
//removeLoadingÓÃÓÚÈ¥µôLoading
function removeLoading(element){
var image = element.getElementsByTagName("img");
for(var i=0;i<image.length;i++){
element.removeChild(image[i]);
}
}
//ajax
function Ajax(statusId, recvType) {
var aj = new Object();
displayLoading(document.getElementById("show"));
var clientHeight = scrollTop = 0;
if(navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
clientHeight = document.body.clientHeight;
scrollTop = document.body.scrollTop;
} else {
clientHeight = document.documentElement.clientHeight;
scrollTop = document.documentElement.scrollTop;
}
if(document.getElementById(statusId)) {
aj.statusId = document.getElementById(statusId);
document.getElementById(statusId).style.top = 10+"px";
} else {
var divElement = document.createElement("DIV");
divElement.id = "xspace-tipDiv";
divElement.className = "xspace-ajaxdiv";
divElement.style.cssText = "width:200px; height:40px; line-height: 40px; text-align: center;";
divElement.style.left = 10+"px";
divElement.style.top = 10+"px";//(clientHeight +scrollTop - 60)
divElement.id = statusId;
document.body.appendChild(divElement);
aj.statusId = divElement;
}
aj.targetUrl = '';
aj.sendString = '';
aj.recvType = recvType ? recvType : 'HTML';//HTML XML
aj.resultHandle = null;
aj.createXMLHttpRequest = function() {
var request = false;
if(window.XMLHttpRequest) {
request = new XMLHttpRequest();
if(request.overrideMimeType) {
request.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject) {
var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
for(var i=0; i<versions.length; i++) {
try {
request = new ActiveXObject(versions[i]);
if(request) {
return request;
}
} catch(e) {
//alert(e.message);
}
}
}
return request;
}
aj.XMLHttpRequest = aj.createXMLHttpRequest();
aj.processHandle = function() {
aj.statusId.style.display = '';
if(aj.XMLHttpRequest.readyState == 4) {
if(aj.XMLHttpRequest.status == 200) {
if(aj.recvType == 'HTML') {
aj.resultHandle(aj.XMLHttpRequest.responseText);
} else if(aj.recvType == 'XML') {
aj.resultHandle(aj.XMLHttpRequest.responseXML);
}
aj.statusId.style.display = 'none';
} else {
aj.statusId.innerHTML = xml_http_load_failed;
}
}
}
¡¡