Closed (fixed)
Project:
RESTful Web Services
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Apr 2013 at 02:53 UTC
Updated:
24 Apr 2013 at 16:51 UTC
I just set up a fresh Drupal 7 site and created 50 articles with the Devel module.
Everything seems to work fine when using a browser, but I can't get the site to return json when using jQuery's ajax function.
I have all necessary permissions granted.
Browser (Chrome, Firefox), also cURL from command line:
http://mysite.local/node.json works fine
http://mysite.local/node/1.json works fine
jQuery (see code below):
http://mysite.local/node.json returns "404 file not found"
http://mysite.local/node/1.json returns the full html page, as if I requested http://mysite.local/node/1
jQuery ajax:
$.ajax({
url: "http://mysite.local/node.json", // I have tried many, many things here. none return json.
type: "GET",
contentType: "application/json",
type: "json",
success: function(result) {
console.log(result);
}
});
Comments
Comment #1
eterps commentedEDIT: looks like it's a problem with my jQuery code. I tried $.getJSON() instead of .ajax() and now it works as expected.
Comment #2
theflowimmemorial commentedClosing as fixed since it was a user error.
Comment #2.0
theflowimmemorial commentedadded code tags around jquery snippet