日期:2014-05-17 浏览次数:20518 次
<%@ Page Title="" Language="C#" MasterPageFile="~/Master/student.master" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="user_test2" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <script type="text/javascript" src="../js/jquery-1.7.js"></script> <script type="text/javascript"> $(function () { $("#<%=ceshi.ClientID %>").click(function () { var bianliang = "3"; alert(“****”);//显示正常 $.ajax({ type: "post", url: "test2.aspx/getschoolajax", contentType: "application/json; charset=utf-8", dataType: "json", data: "citynum=" + bianliang, beforeSend: function (XMLHttpRequest) { $("#schools").text("正在查询..."); }, success: function Msg(data) { $("#schools").css("color", "red"); $("#schools").html("-----data------" + data); }, error: function () { alert("error");//得不到数据,一直提示error } }); }); </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <asp:Button ID="ceshi" runat="server" Text="Button" /> <div id="schools" class="bg1"> <!-- 此处显示学校列表 --> </div> <div> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using PBLL; using PModel; using System.Data; public partial class user_test2 : System.Web.UI.Page { userinfoManager userinfo = new userinfoManager(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected List<string> getschoolajax() { int citynumber = Convert.ToInt32(Request.QueryString["citynum"]); List<string> schoollist = userinfo.getschoolbycitynumberlist(citynumber); if (schoollist.Count != 0) { return schoollist; } else { return null; } } }
/// <summary> /// Serialize object to string of json format /// </summary> private string JsonSerializer<T>(T t) { var ser = new DataContractJsonSerializer(typeof(T)); var ms = new MemoryStream(); ser.WriteObject(ms, t); string jsonString = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); return jsonString; } /// <summary> /// D