html端代码如下:
<html>
<head>
<script src="web/js/CryptoJS/rollups/sha1.js" type="text/javascript"></script>
<script src="web/js/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
<script>
var sha1=CryptoJS.SHA1("abc");
var sha1_Latin=sha1.toString(CryptoJS.enc.Latin1);
$.ajax({
type:'get',
url:"cgi-bin/test2.lua",
data:sha1_Latin,
datatype:"text",
success:function(data){
document.write(data);采用ajax时,输出lua返回iconv.new的返回值cd到屏幕,发现为空值
document.write("<br>");
}
})
</script>
</body>
</html>
lua端代码如下
#!/usr/bin/lua
print [[
Content-Type:text/plain\n\n
]]
require"sha1"
require"iconv"
function check_one(to,from,text)
local cd = iconv.new(to .. "//TRANSLIT", from)
print(cd)
local ostr,err =cd:iconv(text)
if err == iconv.ERROR_INCOMPLETE then
print("ERROR: Incomplete input.")
elseif err == iconv.ERROR_INVALID then
print("ERROR: Invalid input.")
elseif err == iconv.ERROR_NO_MEMORY then
print("ERROR: Failed to allocate memory.")
elseif err == iconv.ERROR_UNKNOWN then
print("ERROR: There was an unknown error.")
end
print(ostr)
return ostr
end
ch=os.getenv("QUERY_STRING")//有无这行对代码有影响
check_one("utf-8","iso-8859-1",sha1_binary("abc"))
ch=os.getenv("QUERY_STRING")是与ajax进行交互的,接收ajax发送的数据,假如注释掉这一行的时候,单独运行lua脚本,则check_one函数可以正常运行,check_one内的cd有返回值;但是当不注释掉这行,lua脚本和ajax交互时,即使lua端不使用接收到的数据ch,check_one依然不能正常工作,输出cd为空,即iconv.new无返回值
为啥不用openresty