当前位置 : 主页 > 网页制作 > html >

html页面提交JSON,ASP页面接收并打印

来源:互联网 收集:自由互联 发布时间:2021-06-12
jsonSubmit.html 1)能过 javascript函数驱动请求页 !DOCTYPE htmlhtmlheadtitle把js的json 传递给asp文件接收并打印/titlemeta charset="utf-8"/headbodyh3 onclick="queryStudent()"请求学生/h3script type="text/javascript"funct

jsonSubmit.html

1)能过 javascript函数驱动请求页

<!DOCTYPE html>
<html>
<head>
	<title>把js的json 传递给asp文件接收并打印</title>
	<meta charset="utf-8">
</head>
<body>
	<h3 onclick="queryStudent()">请求学生</h3>	
	<script type="text/javascript">
		function queryStudent() {
			// body...
		var student = { name:"张三同学",  age:18, city:"江苏宿迁" };
		var myJSON =  JSON.stringify(student);
          //设置接收上传json文件路径 window.location="http://localhost:8078/test/jsonPrint.asp?student="+myJSON } </script> </body> </html>

 2)jsonPrint.asp

 接收JSON并解析打印出来对印子项

<!DOCTYPE html>
<%
    dim student
    student=request("student") 
%>
<html>
<head>
    <title>json return</title>
    <meta charset="utf-8">
</head>
<body>
<%
 实现读取解析方法自定义函数
Dim scriptCtrl  
Function parseJSON(str)  
    If Not IsObject(scriptCtrl) Then  
        Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")  
        scriptCtrl.Language = "JScript"  
        scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"  
    End If  
    scriptCtrl.ExecuteStatement "result = " & str & ";"  
    Set parseJSON = scriptCtrl.CodeObject.result  
End Function  
%>
<%
    set stuJSON=parseJSON(student)
    Response.Write("</h2>学生json原文:"+student+"</h2><br/>")
    response.Write("<h2>学生姓名:"+stuJSON.name+"</h2>")
    response.Write("<h2>学生姓名:"+stuJSON.name+"</h2>")
    response.Write("<h2>学生姓名:"+stuJSON.name+"</h2>")
    set stuJSON=nothing
%>
</body>
</html>
网友评论