我是 MVC 和 jQuery 和 jqPlot 的新手。
谁能举个例子,我可以在哪里找到演示项目或逐步实现的过程。
我需要的是:
- 如何返回 JSON 以查看。
- 添加视图时 - 它应该是部分视图还是普通视图?
- 如何使用 jQuery 从视图中获取 JSON。
- 如何在 jqPlot 中传递 JSON 对象?
提前非常感谢。
================================================
尝试使用下面的代码,它总是会出现错误部分,有人能解释一下是什么原因吗?
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../Scripts/excanvas.js"></script><![endif]-->
<script src="../js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript" >
$(document).ready(function () {
$("#btnClick").click(function () {
alert('Inside Click Function');
$.ajax(
type: 'GET',
url: "JSONSample.aspx/GetItSerialized",
processData: true,
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data.d, function (index, item) {
alert('Inside Success');
});
//alert('Inside Success');
//processData(data);
},
error: function(jqXHR, textStatus, errorThrown) {alert('Error');}
});
function processData(data) {
alert('test');
}
});
});
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="btnClick" runat="server" value="Click here" type="button" />
</div>
</form>
</body>
public string GetItSerialized()
{
Employee oEmployee1 = new Employee { Name = "ABC", ID = "111", Age = "30" };
Employee oEmployee2 = new Employee { Name = "FDF", ID = "rtrt", Age = "31" };
Employee oEmployee3 = new Employee { Name = "dfdf", ID = "fdfd", Age = "20" };
List<Employee> listEmp = new List<Employee>
{
oEmployee1,
oEmployee2,
oEmployee3
};
string str = (new JavaScriptSerializer().Serialize(listEmp));
return str;
}
}
public class Employee
{
public string Name { get; set; }
public string Age { get; set; }
public string ID { get; set; }
}