asp.net后台cs中的JSON格式变量在前台Js中调用方法!(前后台实例!)
[javascript]
//后台cs代码:
//后台cs代码:
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login_jg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string get()
{
string name=this.Request["name"]; // 从另一页获取参数,可以不需要!
string json = "{Name:'" + name + "',Number:'"15"' + "'}";
return json;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login_jg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string get()
{
string name=this.Request["name"]; // 从另一页获取参数,可以不需要!
string json = "{Name:'" + name + "',Number:'"15"' + "'}";
return json;
}
}
前台代码:
[javascript]
var dpinfo = "<%=get() %>";
var dpjson = eval("(" + dpinfo + ")");
alert(dpjson.Name);
var dpinfo = "<%=get() %>";
var dpjson = eval("(" + dpinfo + ")");
alert(dpjson.Name);
补充:Web开发 , ASP.Net ,