52,797
社区成员
发帖
与我相关
我的任务
分享
<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>
#!/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"))
$.ajax({
type: 'get',
url: "cgi-bin/test2.lua",
data: sha1_Latin,
datatype: "text",
success: function (data) {
alert('success:' + data);///////
},
error: function (xhr) {/////////////
alert('发生错误\n'+xhr.responseText)
}
})