Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to use HighCharts in Sharepoint Web Parts. So, I put necessary JS files in 14 hive folder and everything works fine. This is my ScriptLink Tag:

<SharePoint:ScriptLink ID="ScriptLink1" Name="<% $SPUrl:~SiteCollection/STYLES/MyWebPart/Highcharts/js/highcharts.js%>" runat="server" />

But when I want to use AJAX, there is a problem:

I don't know how can I address the AJAX URL:

function requestData() {
        $.ajax({
            url: ' ?? ',
            success: function(point) {
                var series = chart.series[0],
                shift = series.data.length > 20;
                chart.series[0].addPoint(point, true, shift);
                setTimeout(requestData, 1000);    
            },
            cache: false
        });
}

I have tested this solution without a chance:

url: '< % = ResolveUrl("$SPUrl:~SiteCollection/STYLES/MyWebPart/data.json") % >'

Even if I use full URL I got Runtime Error with FireBug (Net Tab): (In this situation if I use incorrect URLs I got 404 Not Found Error)

url: 'http://sharepoint/_layouts/1033/STYLES/MyWebPart/data.json'

At last if I use HighChart URL with "crossDomain: true" nothing happens:

url: 'http://www.highcharts.com/studies/live-server-data.php'

It seems Web Parts have some problems with AJAX.

Any help would be greatly appreciated

share|improve this question
    
Where is your data.json file? Have you tries jQyery.ajax instead of $.ajax? –  Per Jakobsen Apr 11 '12 at 7:28
    
Thank you for your response. Yes, I trid. The data.json file is in the "_layouts/1033/STYLES/MyWebPart/" folder where jQuery and HighCharts is there too. –  Natasha Apr 11 '12 at 8:35
    
Then specifying '/_layouts/1033/STYLES/MyWebPart/data.json' as url should work. What is fiddler giving you for that? –  Per Jakobsen Apr 11 '12 at 8:42
    
Server Error in '/' Application. (Runtime Error) and it says: set <customErrors mode="RemoteOnly"/> in web.config. But I don't have web.config file in WebPart Solution. –  Natasha Apr 11 '12 at 9:17
    
Change the web.config in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS –  Per Jakobsen Apr 11 '12 at 9:31
show 1 more comment

1 Answer

up vote 1 down vote accepted

Due to this line:

<add name="JSONHandlerFactory" path="*.json" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="Unspecified" preCondition="integratedMode" />

in the <system.webServer><handlers> section in the standard SharePoint 2010 web.config. SharePoint (well in fact ASP.NET) assumes that any file with the extension .json should be json enabled web services.

So if your data.json is just data then you have to give it another extension.

share|improve this answer
    
Thank you Per Very Much. It works now with another extension. So, how can I call a .json file? How can I use this web service? Any references? –  Natasha Apr 11 '12 at 10:11
    
There is one article here –  Per Jakobsen Apr 11 '12 at 10:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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