Я пытаюсь следовать пример одной странице App hereВозвращение JSON данные WebMethod и sammy.js
Направо где JSON должен быть разобран, я получаю ошибку: SyntaxError: JSON.parse: неожиданный характер если я не укажу dataType: 'json' Если я помещал dataTyp: 'json', то ошибок не было, но json не возвращался, и мой шаблон не был заполнен.
Я поставил сетку только, список возвращался ... и это так.
Я загрузил jquery, sammy.js, json2.js и sammy.template.js..все последние и самые большие.
Я знаю, что это пример приложения на сайте diff, и я ценю время ваших ребят. Мне просто нравится следовать и понимать, потому что приложения SPA интересны.
JavaScript:
$(document).ready(function() {
//alert('Jquery has loaded');
var loadOptions = { type: 'get', dataType: 'json', cache: false };
var app = $.sammy('#sammyDiv', function() {
this.use('Template');
this.use('Session');
this.around(function (callback) {
var context = this;
this.load('Default.aspx/GetEmployees', { cache: false }) // loadOptions) // { dataType: 'json', cache: false })
.then(function (items) {
context.items = JSON.parse(items).d; // browser parser... I believe it fails right here
//context.items = $.parseJSON(items).d; //jQuery handling
//alert(context.items);
//context.items = JSON.stringify(items);
})
.then(callback);
});
CS код:
static List<Employees> emps;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
emps = new List<Employees>();
Employees emp = new Employees("Kedar", "Kulkarni", "0001", "A");
Employees emp1 = new Employees("ABC", "XYZ", "21211", "B");
emps.Add(emp);
emps.Add(emp1);
}
/* using foreach method
foreach (Person person in persons)
{
Response.Write(String.Format("Name : {0} Age : {1} Address : {2} Job : {3}", person.Name, person.Age, person.Address, person.Job));
Response.Write("</br>");
}
*/
this.GridView1.DataSource = emps; //for testing to see if my list gets returned
this.GridView1.DataBind();
}
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public static List<Employees> GetEmployees()
{
return emps;
}