0

I used the below code to get list items but it is going to error function and showing error in alert.

<html lang="en-US">
<head>
    <meta charset="UTF-8">
</head>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
    function insightViewModel() {
        var self = this;
        self.insights = ko.observableArray([]);
        self.GetInsights = function () {
            $.ajax({
                url: "http://demo/sites/Dev/_api/lists/getbytitle('CountryNames')/items",
                type: "GET",
                headers: {
                    "accept": "application/json;odata=verbose",
                },
                success: function (data) {
                    debugger;
                    alert("Get data-"+data.d.results);
                   self.insights.push(data.d.results);
                },
                error: function (error) {
                    alert(JSON.stringify(error));
                }

            });
        }
        self. GetInsights();
    }
        $(document).ready(function () {
         insightModel = new insightViewModel();
        var insightDiv = document.getElementById("divDatabinding");
            insightViewModel();
        });
    //


</script>
<body>
<div id="divDatabinding"> 
    <table >
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                    </tr>
                                </thead>
                                <tbody data-bind="foreach:insights">
                                    <tr>
                                        <td style="white-space: nowrap">
                                            <span class="spanlink" data-bind="click: function () { $root.RulesopenEditPanel($data) }">
                                                <i class="fa fa-chevron-circle-up"></i>
                                            </span>
                                        </td>
                                        <td style="white-space: pre-wrap" data-bind="text: Title"></td>

                                            <span class="spanlink" data-bind="click: function () { $root.RulesdeleteRecord($data) }">
                                                <i class="fa fa-times"></i>
                                            </span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

</div>
</body>
</html>

I am getting this error...

enter image description here

1
  • What error are you getting, please try to be as detailed as possible in your questions Commented Nov 3, 2015 at 7:45

1 Answer 1

3

Your REST-url is wrong, you are missing /web.

It should be

http://demo/sites/Dev/_api/web/lists/getbytitle('CountryNames')/items
4
  • wow - that's a quick edit @Robert Lindgren - you beat me to it!
    – tarjeieo
    Commented Nov 3, 2015 at 7:56
  • Doing some server side code, so recycle time = edit time ;) Commented Nov 3, 2015 at 8:00
  • after using web also it is showing same error
    – KumarV
    Commented Nov 3, 2015 at 8:36
  • What do you get if you access the URL in the browser?
    – tarjeieo
    Commented Nov 3, 2015 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.