0

I have this code to display a share price which we embed in a script editor webpart and it works fine on SP2010 but not SP2013 - it just simply never refreshes. Is Json blocked by default?

BTW I've taken a portion of the code to paste below so it's missing several other share price code so some basic xml may be wrong.

<div id="out1a" style="width: 400px">
<div style="padding-bottom: 2px !important; padding-top: 2px !important; padding-left: 2px !important; padding-right: 2px !important">
<div style="font-weight: bold; text-decoration: underline">&#160;</div>
<div style="padding-top: 0px">
<div style="overflow: hidden; float: left; color: white; text-align: right; padding-top: 3px; text-decoration: none; width: 120px"><a href="http://www.google.co.uk/finance?q=123" target="tab" style="color: #891336">Company Name</a></div>
<div style="float: left; color: black; text-align: right; padding-top: 3px; width: 80px">248.37p</div>
<div style="float: left; color: #ff0000; text-align: right; padding-top: 3px; width: 80px">-7.63p</div>
<div style="float: left; color: #ff0000; text-align: right; padding-top: 3px; width: 80px">-2.98%</div>
<br/>
</div>

<script type="text/javascript">
$(function () {
    $.ajax({
        type: "GET",
        url: "http://myinternalwebsite",
        dataType: "jsonp",
        success: function (data) {
            $('#out1a').html(data);
        }
    });
  }
 );
 </script>
3

In SharePoint 2013 you can't use Content Editor Webpart for embedding JavaScript. Instead you should move it to Script Editor Webpart.

Another option is to store the HTML and Script in a file. And then reference that file in the Content Editor webpart using the Content Link property.

1

Hi MJJM and welcome to SP.SE

Try the following:

jQuery.ajax({
    url: "http://myinternalwebsite/_api/web/lists",
    type: "GET",
    headers: { 
        "accept": "application/json;odata=verbose",
    },
    success: function(result) { console.log(result)},
    error: function(error) { console.log(error)}
});

In your case you have to tell SharePoint what you want, e.g. add _api behind your url. Additionally you have to tell SharePoint in what format, here the accept header.

This is a really good starter article: http://msdn.microsoft.com/en-us/library/office/jj164022%28v=office.15%29.aspx

  • Thanks Max, unfortunately that doesn't work but I made a mistake and it's a content editor webpart I'm using not a script editor - does that make a difference? I've change the URL to the below jQuery.ajax({ url: "website/sharepoint/api/SP/Shares/SharePrice/5", type: "GET", headers: { "accept": "application/json;odata=verbose", }, success: function(result) { console.log(result)}, error: function(error) { console.log(error)} }); – MJJM Jan 7 '15 at 10:56
  • Your url is not correct. The _ is missing and /SP/Shares/SharePrice/5 is not a valid syntax. What do you wanna get? – Max Melcher Jan 7 '15 at 15:38
  • Hey Max, thanks for the response. I turns out that we didn't have the required jquery file in the 15 hive on the web servers for SharePoint and somehow the code that our old developer wrote was dependant on that! We added the file and voila it worked! – MJJM Jan 15 '15 at 11:32

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.