asp怎么传值给ajax?

来源:百度知道 编辑:UC知道 时间:2024/05/12 08:02:57
asp页面使用ajax,asp接收到ajax的数据,处理完成后,怎么把结果传递给ajax啊,试过Response.Write()不行的。
ajax接收用的ajax.responseText属性,可alert出来是整个页面。
请问怎么才能让ajax接收到asp的返回值?多谢了。

简单,aps页面什么多余的东西都不写,比如:
<!--#include file="conn.asp"-->
<%
dim str
str=""
Response.CharSet = "GB2312"

set rs=server.createobject("adodb.recordset")
sql="select name from flow"
rs.open sql,conn,3,3
if not rs.eof then
rs.movefirst
while not rs.eof
classname=rs("name")
str=str & classname & ","
rs.movenext
wend
response.Write(str)
end if
%>
用ajax的responseText接受到的就是str
注意,这个页面内不要包含任何html的东西,如<html><body>之类,否则都会传递过去。
Response.CharSet = "GB2312"是为了得到的中文不出现乱码

只要你的asp代码中“response.write”能返回出值来,ajax就能接收到。ajax是用responseText,responseXML或responseBody接收asp中write的值的。
对于alert出整个画面,请给代码我看看