0
我是新來的MVC和jQuery和jqPlot。jqPlot圖表使用asp.net MVC,JSON
任何人都可以舉例說明我可以找到演示項目或逐步過程到達。
我需要的是:
- 如何返回一個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; }
}