后台:引用 using System.Reflection;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string method = Request.QueryString["Method"];
if (!string.IsNullOrEmpty(method))
{
MethodInfo methodInfo = this.GetType().GetMethod(method);
methodInfo.Invoke(this, null);
}
}
}
//接口方法
public void GetTest()
{
string json = string.Empty;
try
{
json = SerializerJson.SuccessFlagToJson(-1, "测试");
}
catch (Exception ex)
{
json = SerializerJson.SuccessFlagToJson(-1, ex.Message);
LogProxy.Error(ex.Message);
}
Response.Clear();
Response.Write(json);
Response.End();
}
前台:
<script>
$(function () {
//加载菜单
$.ajax({
url: 'main.aspx?Method=GetTest',
dataType: "json",
type: "POST",
data: {
phone: txtUserName
},
success: function (result) {
if (result.total == 1) {
location.href = "main.aspx";
}
else {
layer.alert(result.msg, { icon: 0 });
}
}
});
});
</script>