'JSON' undefined in RiaServices.Jquery


  • 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 type="text/javascript">
        $(document).ready(function () {

            var friends = [];

            var ds = $([friends]).dataSource({
                serviceUrl: "/MVCTEST-DomainService1.svc",
                queryName: "GetFriendSet",
                bufferChanges: true

            $("#btnLength").click(function () {
            $("#btnInsert").click(function (event) {
                var insertFriend = { Name: friend.Name(), Age: friend.Age(), Sex: friend.Sex(), Country: friend.Country() };
                $.observable(friends).insert(friends.length, insertFriend);


    Tuesday, March 13, 2012 11:02 AM

All replies