Asp.Net MVC2.0 Jquery Json

來源:互聯網
上載者:User
 

Asp.Net MVC2.0 Jquery Json  
 3  4 <script type="text/javascript">
 5     function postBBSData() {
 6                 var da = $("#bbscontent").val();
 7                 $.ajax({
 8                     type: "GET",
 9                     url: "/home/GetBBSJsonData",//MVC2.0中 Controller:Home,Action:GetBBSJsonData
10                     data: "txt=" + da + "&pid=bb&userid=gxw",//運用的GET類型,也可以用POST,只需要底層代碼修改下
11                     dataType: "json",                       //傳回值為JSON了性
12                     success: function (msg) {
13                         var p = "<span>" + msg.UserID + "</span><span>" + msg.Context + "</span>"
14                         $("#BBSTr").appendTo(p);
15                     }
16                 });
17             }    
18 </script>
19 
20  <div id="BBSTr">
21                     <span>11111</span>
22                 </div>
23                 <table>
24                     <tr>
25                         <td>
26                             使用者名稱:<%=Html.TextBox("bbsuserid") %>
27                         </td>
28                     </tr>
29                     <tr>
30                         <td>
31                             內容:<%=Html.TextArea("bbscontent")%>
32                         </td>
33                     </tr>
34                     <tr>
35                         <td>
36                             <input type="submit" onclick="postBBSData();" value="提交" />
37                         </td>
38                     </tr>
39                 </table>
40 
41 
42 Controller:
43 
44    public JsonResult GetBBSJsonData()
45         {
46             string context = Request.QueryString["txt"].ToString();
47             string productID = Request.QueryString["pid"].ToString();
48             string userId = Request.QueryString["userid"].ToString();
49             var p = new//這也是一種類型的JSON
50             {
51                 Context = context,
52                 UserID = userId,
53                 CurrentTime = DateTime.Now.ToString()
54             };
55             return Json(p, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet為了Get傳值不出錯
56         }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.