针对不支持AJAX异步查询的虚拟空间做跨站点查询

最近在做一个ASP+ACCESS的企业小站,因为有中文、英文版分开不同空间不同域名的需求。原构想用AJAX做异步查询相关质保数据,但上线了才发现新网的虚拟空间不支持AJAX异步,咨询客服后也没有效的方法。后来想到:远程JS应该是每天的,把数组做成JS的数据,再做数据组的展示,也能达到异步查询的功能。

一、生成JS数组的ASP代码

<% Response.Charset="gbk" %>
<% Session.CodePage=936 %>
<!--#include file="inc/Conn.asp"-->
let zbarr = [
<%
typer=Request("qtyper")
key=Request("key")

If typer<>"" and key<>"" Then
	Set rs=server.createobject("adodb.recordset")
	sql="select * from table1 where 1=1"
	if typer="1" then
		sql=sql&" and cjhm='"&Ucase(key)&"'"
	elseif typer="2" then
		sql=sql&" and cphm='"&Ucase(key)&"'"
	elseif typer="3" then
		sql=sql&" and mjhm='"&Ucase(key)&"'"
	elseif typer="4" then
		sql=sql&" and czdh='"&Ucase(key)&"'"
	else
		sql=sql&" and cjhm='"&Ucase(key)&"'"
	end if	
	sql=sql&" order by id desc"
	rs.open sql,conn,1,1
	i=0
	do while not rs.eof
	   v_enddate=rs("enddate")
	   If rs("appflag")="1" Then
			if len(v_enddate)=10 and isdate(v_enddate) Then
				If DateDiff("d", Year(Now)&"-"&Month(Now)&"-"&Day(Now), v_enddate)<0 then
					stauts="<font color=#ff6666>Expired</font>"
				Else
					stauts="<font color=green>Valid</font>"
				End If
			else	
				stauts="<font color=red>Pending approval</font>"
			end if
	   Else
		stauts="<font color=red>Pending approval</font>"
	   End If
	   If trim(rs("url"))>"" Or trim(rs("url1"))>"" Or trim(rs("url2"))>"" Or trim(rs("url3"))>"" Or trim(rs("url4"))>"" Or trim(rs("url5"))>"" Then
			If trim(rs("url"))>"" Then zburl=rs("remark")&"<br><img src='https://www.xxxxx.cn"&rs("url")&"' /><br>" End If
			If trim(rs("url1"))>"" Then zburl1=rs("remark1")&"<br><img src='https://www.xxxxx.cn"&rs("url1")&"' /><br>" End If
			If trim(rs("url2"))>"" Then zburl2=rs("remark2")&"<br><img src='https://www.xxxxx.cn"&rs("url2")&"' /><br>" End If
			If trim(rs("url3"))>"" Then zburl3=rs("remark3")&"<br><img src='https://www.xxxxx.cn"&rs("url3")&"' /><br>" End If
			If trim(rs("url4"))>"" Then zburl4=rs("remark4")&"<br><img src='https://www.xxxxx.cn"&rs("url4")&"' /><br>" End If
			If trim(rs("url5"))>"" Then zburl5=rs("remark5")&"<br><img src='https://www.xxxxx.cn"&rs("url5")&"' />" End If
	   End If
	%>{czdh:"<%= rs("czdh") %>",cphm:"<%= rs("cphm") %>", cjhm:"<%= rs("cjhm") %>",mjhm:"<%= rs("mjhm") %>",dmmc:"<%= rs("dmmc") %>",czdate:"<%= rs("czdate") %>",enddate:"<%= rs("enddate") %>",zbdh:"<%= rs("zbdh") %>",fwms:"<%= rs("fwms") %>",stauts:"<%= stauts %>",zburl:"<%= zburl %>",zburl1:"<%= zburl1 %>",zburl2:"<%= zburl2 %>",zburl3:"<%= zburl3 %>",zburl4:"<%= zburl4 %>",zburl5:"<%= zburl5 %>"},
	
		<% 
		i=i+1 
		rs.movenext 
		loop 
		rs.close
		set rs=nothing
End If
%>
];

二、展示JS数组数据的写法

<div class="pageContent" id="zblist"></div>

<SCRIPT src="js/jquery-1.11.3.min.js?rd=<%=currentDateTime %>"></SCRIPT>
<script src="https://www.xxxx.cn/yc_xxx_js.asp?qtyper=<%=typer %>&key=<%=key %>&rd=<%=currentDateTime %>"></script>
<script language="JavaScript" type="text/JavaScript">
$(function() {
	var discount = $('#zblist');//要展示的层ID
	var arrText = [];
	var counti=0;
	var htmlContent = discount.html();
	// 使用for循环遍历数组
	for (let i = 0; i < zbarr.length; i++) {
	  let zbinfo = zbarr[i];
	  arrText.push('<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">');
	  arrText.push('<tr><td width="30%" class="zbtitle">License plate number:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.cphm +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Frame number:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.cjhm +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Membrane roll number:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.mjhm +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Name of the store:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.dmmc +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Date of operation:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.czdate +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Termination date:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.enddate +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Warranty policy number:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.zbdh +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Service description:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.fwms +'</td></tr>');
	  arrText.push('<tr><td class="zbtitle">Service status:</td><td style="padding-left:5px;text-align:left">'+ zbinfo.stauts +'</td></tr>');
	  if(zbinfo.zburl != "") {
		arrText.push('<tr><td colspan="2" class="zbcont">'+ zbinfo.zburl + zbinfo.zburl1 + zbinfo.zburl2 + zbinfo.zburl3 + zbinfo.zburl4 + zbinfo.zburl5 +'</td></tr>');
	  }
	  arrText.push('</table>');
	  arrText.push('<p>&nbsp;</p>');
	  counti++;
	}
    //如果远程有数据,清空当前无数据字样
	if(counti>0 && htmlContent.indexOf("No relevant records") !==-1){
		 discount.html('');
	}
	discount.append(arrText.join(''));
})
</script>

希望对你有帮助!点个赞就是最大的动力!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值