.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>

四、效果演示:

提交

右鍵查看源碼

相關文章
相關標籤/搜索