@{ Layout = null; } <script src="../../Scripts/jquery-1.10.2.min.js" type="text/javascript"></script> <script type="text/javascript">
$(document).ready(function () { $("#btnSubmit").click(function () { $.ajax({ url: "/HelloWorld/test", type: "POST", dataType: "text", data: { username: $("#txtName").val(), email: $("#txtEmail").val() }, success: function (data) { console.log("正确:"); //console.log(data); var str = ‘{"name":"sole","age":"24"}‘; var _d = JSON.parse(str);//字符串转json console.log(_d.name); //var json = JSON.parse(data); //console.log(json.msg); $("#result").html("success"); $("#result").css("color", "red"); }, error: function (e) { console.log("错误:"); console.log(e); } }); }); });
</script> <table border="2"> <tbody> <tr> <td colspan="2" align="center">User Regis Demo</td> </tr> <tr> <td>NAME:</td> <td><input type="text" id="txtName" style="width:160"></td> </tr> <tr> <td>Email:</td> <td><input type="text" id="txtEmail" style="width:160"></td> </tr> <tr> <td><input type="button" id="btnSubmit" value="submit" style="width:160"></td> </tr> </tbody> </table> <div id="result">Jquery Ajax Call Result Will Display here...</div>
public void test(string username, string email) { string str = "{\"success\":\"true\",\"msg\":\"添加成功\"}"; //string str = "Hello: [" + username + "] your eamil is : [" + email + "]"; Response.Write(str); }
时间: 2024-10-10 10:46:52