Reputation: 31
I have a website that works fine when I am running it locally off of the file system, but when I try to run the same site using a local web server it breaks. If I use a post I get a 405 Method Not Allowed error. If I use a get call then I receive 404 Not Found.
What I think: It has something to do with the Same Origin Policy, I have sen similar questions, but have not been able to get my code working using those answers.
The website is all HTML and JavaScript, I am using IIS 7.5 as my web server. I am also using the jQuery 1.9 library to make the AJAX calls. The call and its contents are posted below(in the post version).
$.get('js/questionJSON.json', function(data){
var template = $('#optionTemplate').html();
var li = $('#templateLI').html();
var partials = {"templateLI": li}
var html = Mustache.render(template,data, partials);
$('#questionHolder').append(html);
$('#sortable li .destroyer').click(destroyer);
$('#sortable li .correctnessGauge').click(correctnessChanger);
$('.dropdown-toggle').dropdown();
$( "ul, li" ).disableSelection();
$('#adder').click(createNewListItem);
$('.dropdown-menu a').click(changeMenuText);
$('#ready2GoBtn').click(createQJSON);
$( "#sortable" ).sortable({
revert: true,
handle: ".handler",
create: numberItems,
stop: numberItems
});
},'json');
Also here are the headers
Response Headers
Cache-Control private
Content-Length 7265
Content-Type text/html; charset=utf-8
Date Wed, 10 Jul 2013 19:39:57 GMT
Server Microsoft-IIS/7.5
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Host 192.168.200.175:90
Referer http://192.168.200.175:90/multi_choice.html
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
X-Requested-With XMLHttpRequest
I know close to nothing about web servers, so if the answer to my question would be best explained by some reference resource I would also appreciate a pointer to that.
Upvotes: 2
Views: 1623
Reputation: 31
Note to anyone who runs into this. It took me about a day to figure it out. First off Blender was right about the POST requests, I changed them to GET requests.
Secondly the issue, as I found out lied not within my code, but with IIS 7.5. It does not come with json as a predefined MIME type. Here are the steps in order to solve this.
1)Make sure you are running IIS 7.5.
2)Open the IIS Services Manager.
3)Open up MIME Types
4)Add a new MIME type
5) There are two fields to fill out.
File Name Extension: JSON
MIME Type: application/json
After that it should work.
Upvotes: 1