'JSON' undefined in RiaServices.Jquery
-
Dienstag, 13. März 2012 11:02
i tried knockout with RiaService.jQuery
and i make a model with DomainService.
and i want to CRUD . but i got a model size. but i can't Insert, Update and Delete
but i don't know why.
error message is 'JSON' undefined. and encodedParameters = JSON.stringify(parameters);
and this is my code.
=======================================================================
@model MVCTEST.Friend
<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>
<script src="@Url.Content("../../Scripts/ria.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/knockout.js")" type="text/javascript"></script>
<script src="~/Scripts/knockout.debug.js" type="text/javascript"></script>
<p>Friend Index : <input type="text" data-bind="value:friend.Id" /></p>
<p>Friend Name : <input type="text" data-bind="value:friend.Name" /></p>
<p>Friend Age : <input type="text" data-bind="value:friend.Age" /></p>
<p>Friend Sex : <input type="checkbox" data-bind="checked:friend.Sex" /></p>
<p>Friend Country : <input type="text" data-bind="value:friend.Country" /></p><hr />
<input type="button" id="btnLength" value="Length" />
<input type="button" id="btnInsert" value="Insert" /><hr />
<div id="divLength" />
<div id="divInsert" /><hr />
<script type="text/javascript">
var friend = {
Id: ko.observable(1),
Name: ko.observable('Lee'),
Age: ko.observable(26),
Sex: ko.observable(true),
Country: ko.observable('Korea')
};
var viewModel = function () {
this.friend = friend;
};
ko.applyBindings(new viewModel());
</script><script type="text/javascript">
$(document).ready(function () {var friends = [];
var ds = $([friends]).dataSource({
serviceUrl: "/MVCTEST-DomainService1.svc",
queryName: "GetFriendSet",
bufferChanges: true
}
);
ds.refresh();$("#btnLength").click(function () {
$("#divLength").html(friends.length);
});
$("#btnInsert").click(function (event) {
var insertFriend = { Name: friend.Name(), Age: friend.Age(), Sex: friend.Sex(), Country: friend.Country() };
$.observable(friends).insert(friends.length, insertFriend);
ds.commitChanges();
});});
</script>
Alle Antworten
-
Mittwoch, 14. März 2012 06:42Moderator
Hi,
check you are using JSON2, if you have already installed DivX software, please disabling Divx addons. and also make sure that your page is rendering in IE8 standards mode. You could refer the following similar post.http://stackoverflow.com/questions/1801835/bizarre-javascript-json-undefined-error
Regards,
PeterPlease mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
-
Mittwoch, 14. März 2012 12:41
sorry. i can't understand
how i can check JSON2? and what is that DivX software?

