1

Why the following code does not work? What do I need to do?

<script src="<MyServerName>/SiteAssets/jquery-1.9.1.js"></script>
<script src="<MyServerName>/SiteAssets/jquery-ui-1.10.3.custom.min.js"></script>

<script language="javascript" type="text/javascript">

        $(document).ready(function () {
         var listUrl =  "http://<MyServerName>/subsite/lists/getbytitle(‘products’)/items";
        $.ajax({  

    url: listUrl,    
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" }, 
    success: function(data) { 
     alert('success');                                  
     for (var i=0; i<data.d.results.length; i++)  
     { 
       var dataCategory = data.d.results[i];   
       alert(dataCategory.Title); 
     } 
   }

   });  
 });  

</script>
4

You are missing the _api/web directive in the url:

var listUrl = "http://<MyServerName>/subsite/_api/web/lists/getbytitle('products')/items"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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