Simple fetching of json file

Aug 13, 2014 at 4:38 AM
In my sharepoint site, I have a web-application running as a subsite in IIS. I want a page on that site to load up a json file via jquery. The page works out of sharepoint through the file system, but when I run it on the server it does not work.

I have a really detailed explanation of my question already here.

Can I use spservices to fill in what is necessary for me to fetch the json object?
Coordinator
Aug 13, 2014 at 12:26 PM
I've added the same answer to your original post on StackExchange.

You don't need SPServices for this. Fetching a JSON file from inside SharePoint should be a simple $.get() or $.getJSON call. Since you didn't post your code, I'm not sure what the issue is, but you should be able to fetch any valid JSON file which accessible via a URL.

M.
Aug 13, 2014 at 2:26 PM
Mr. Anderson, thanks so much for answering. Really, so I should be able to fetch that no problem? The json file is in the root virtual folder of the web-application. I added the snippet to my stack exchange site. I asked here with the intention of seeing if spservices could help me. It's not really a repeat, rather it's a simliar inquiry, I think. Would you be so kind as to check out my question again? I appreciate your time.
Coordinator
Aug 13, 2014 at 2:52 PM
Edited Aug 13, 2014 at 2:52 PM
I just added a few more thoughts to your StackExchange post.

M.
Coordinator
Aug 13, 2014 at 2:59 PM
p.s. Here's a post from my blog where I use $.getJSON() to read a file from a SharePoint Document Library:
http://sympmarc.com/2014/02/18/getting-around-sharepoints-threshold-limits-for-large-reference-lists/

M.
Aug 13, 2014 at 4:01 PM
Mr. Anderson,

Thank you for your attention! I just realized that my web-app was NOT using .NET 4.0. So I'm trying to fix that.

On 8/13/2014 8:59 AM, sympmarc wrote:

From: sympmarc

p.s. Here's a post from my blog where I use $.getJSON() to read a file from a SharePoint Document Library:
http://sympmarc.com/2014/02/18/getting-around-sharepoints-threshold-limits-for-large-reference-lists/

M.

Coordinator
Aug 13, 2014 at 4:05 PM
That shouldn't matter. But why are you running some sort of web-app? You're doing this in SharePoint, right? I think you've lost me.

M.
Aug 13, 2014 at 4:10 PM
Well, I have some other things that I want to be in my sharepoint portal that require .net 4. So I started a web-app under sharepoint which only runs .net 2. The web-app itself is just .net.



On 8/13/2014 10:05 AM, sympmarc wrote:

From: sympmarc

That shouldn't matter. But why are you running some sort of web-app? You're doing this in SharePoint, right? I think you've lost me.

M.

Coordinator
Aug 13, 2014 at 4:18 PM
I think you're creating a mess for yourself.

The bottom line is that you can fetch a JSON file with jQuery with no problem as long as it has a URL.

M.
Aug 13, 2014 at 4:30 PM
Mr. Anderson,

I think you are right. I don't know why it won't fetch the URL, however. I had the json file at the root of the virtual directory for the web-app and was getting the problem, so I am trying to fetch it from a sharepoint library now. I don't know what else to do. The library works fine in a regular .net site in IIS, but when I put it under sharepoint it doesn't work. I'm sorry to bother you so much!

On 8/13/2014 10:18 AM, sympmarc wrote:

From: sympmarc

I think you're creating a mess for yourself.

The bottom line is that you can fetch a JSON file with jQuery with no problem as long as it has a URL.

M.

Aug 13, 2014 at 5:08 PM
Well, without messing with the .net configuration, using the web-application under sharepoint, I cannot load the json file from the root of that virtual directory. The library works through the file system, but not on the server. It gives error 500 when trying to serve the json file. Now, I've added the MIME type for json, but is there something else I need to do? It will work okay in IIS as a regular site, just not in a web-app under Sharepoint.
Aug 13, 2014 at 5:26 PM
Okay, so I tried putting the gg_orgchart files in a virtual directory - not in a sub web-application. The path of sharepoint is http://my.portal.com and the virtual directory is http://my.portal.com/orgchart - I get the same 500 error telling me: _[HttpException]: The page must have a <%@ webservice class="MyNamespace.MyClass" ... %> directive._

So I'm back to the start. The library works in a regular IIS7 .net 2.0 site. It's all html and javascript. There's something in Sharepoint that prevents the json file from being loaded. Maybe I DO need a webservice.
Coordinator
Aug 20, 2014 at 3:25 AM
There's nothing in SharePoint that is preventing the file from being retrieved. Just stick into into a Document Library and retrieve it from that URL to prove it to yourself. You can't retrieve files from the server file system unless they are available via a URL.

M.
Aug 20, 2014 at 3:38 AM
Mr. Anderson, maybe you are right in principle. But I definitely cannot fetch the json from either the file system or the document libray. Everything works fine when loaded into a non-sharepoint site, but as soon as I try to use that in sharepoint, it fails. I have no clues at this point either, although I certainly appreciate your time. If I knew what to tell you to help you understand further, I would tell you! Something in Sharepoint prevents it from working.
Aug 20, 2014 at 12:09 PM
Is your sharepoint system configured to not allow .json files to be served? I have ran across a system that did not allow it. I had to rename the file with a txt extention.




--
Paul T.

-- Sent from Mobile

Aug 20, 2014 at 3:26 PM
Well, I never configured it not to. However, as you mention it, that does seem to work! It won't work with the json extension, but it will work with the txt extension.
Aug 20, 2014 at 3:39 PM
You say you never reconfigured it to not work, but did you configure it TO work?
If you click on a .json file, inside a Document Library what happens? If the file opens up in the browser, then its configured to "server" .json files... if you get the Download dialog, its not.

_________
Paul T

Aug 20, 2014 at 3:45 PM
I added json to the MIME types in IIS. Is there something I need to do for sharepoint? The file does not open in the browser. If the json file is in a document library and I click on it, I get an error:

An error occurred during the processing of /Documents/demo.json. The page must have a <%@ webservice class="MyNamespace.MyClass" ... %> directive.
Aug 20, 2014 at 4:09 PM
Hmmm That's outside of my knowledge base... sorry.. Maybe Mark or "google" can get you an answer :)

​I knew about the issue because I encountered the issue recently on a very restrictive sharepoint setup​... because I was building a solution that needed to work on "all" setups, I just change to using a .txt extension... jQuery's .getJSON will still work..
Aug 20, 2014 at 4:25 PM
Thanks for your attention - I appreciate the help. I should have thought to use a text file in the first place. At least I know my scripts are all working.