本文介绍了如何在JSON字符串中使用TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在按下Button1执行GetDateTime()之前键入的TextBox1没有注册数字或字符串:The TextBox1 is not registering a number or string when typed in before the Button1 is pressed executing GetDateTime():var jsonid = $("#<%= TextBox1.ClientID %>").text();var json1 = "{'id': '" + jsonid + "'}"; 没有错误代码,ID:之后没有打印出来。 Default.aspxThere is no error code there is just nothing printed out after "ID:".Default.aspx<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script type="text/javascript"> function GetDateTime() { var jsonid = $("#<%= TextBox1.ClientID %>").text(); var json1 = "{'id': '" + jsonid + "'}"; $.ajax ({ type: "POST", url: "Default.aspx/GetServerDateTime", data: json1, contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { alert(result.d); }, error: function (status, ex) { alert("Error Code: Status: " + status + " Ex: " + ex); } }); }</script><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="AJAX" OnClick="Button1_Click" /> Default.aspx.csDefault.aspx.csprotected void Button1_Click(object sender, EventArgs e){ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "javascript", "Javascript:GetDateTime();", true);}[System.Web.Services.WebMethod]public static string GetServerDateTime(string id){ string datetimeid1 = "ID: " + id + " Date&Time: " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); return datetimeid1;}推荐答案 没有错误代码,ID:之后没有打印出来。 Default.aspxThere is no error code there is just nothing printed out after "ID:".Default.aspx<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script type="text/javascript"> function GetDateTime() { var jsonid =<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="AJAX" OnClick="Button1_Click" /> Default.aspx.csDefault.aspx.csprotected void Button1_Click(object sender, EventArgs e){ ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "javascript", "Javascript:GetDateTime();", true);}[System.Web.Services.WebMethod]public static string GetServerDateTime(string id){ string datetimeid1 = "ID: " + id + " Date&Time: " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt"); return datetimeid1;} 这篇关于如何在JSON字符串中使用TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 20:00