MVC 异步请求

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index1</title>
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script>

        function suc(obj) {
            alert(obj);
            function err(xhr) {
                alert(xhr.readystate);
            }
        }
    </script>
   
</head>
<body>
    <div>
    
       <h1>异步</h1>
     @using(Ajax.BeginForm("GetData", "Home", new AjaxOptions()
       {
         HttpMethod="Post",
         OnSuccess="suc",
          OnFailure="err", 
         LoadingElementId="imgLoad"
       })){
        <input type="text" name="txtname" value=" " />
        <input type="submit"  />
       
        }
    </div>
   

</body>
 public ActionResult GetData()
        {
            string str = Request.Form["txtname"];
            
            return Content(str+" "+DateTime.Now.ToString());
        }

 

posted @ 2015-09-20 13:45  每天进步一点点!  阅读(399)  评论(0编辑  收藏  举报