.net 接口返回json格式示例

一、新建 InterfaceTestPro1 项目:html

FILE - New - Project... - Web - ASP.NET Web Forms Applicationpost

name:InterfaceTestPro1spa

二、新建 test.ashx 项:3d

项目右键 - Add - New Item.... - Generic Handlercode

name:test.ashxorm

将 ProcessRequest 方法替换成以下代码xml

            context.Response.ContentType = "text/plain";
            RspMsg rspMsg = new RspMsg();
            string name = context.Request.Form["name"].ToString();
            rspMsg.ReturnCode = "1";
            rspMsg.ReturnMessage = "Welcome " + name;
            context.Response.Write(rspMsg.ToString());

三、新建 test.html 项:htm

项目右键 - Add - New Item.... - HTML Pageblog

name:test.htmlinput

代码以下

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <form name="form1" method="post" action="test.ashx">
        name:  <input type="text" name="name" value=""/>
        <input type="submit" value="submit"/>
    </form>
</body>
</html>

四、效果演示:

提交

右键查看源码

相关文章
相关标签/搜索