Hello everyone,
I'm frustrated because what I want to achieve is supposed to be simple stupid. I'm simply trying to access product information from an outside non drupal site.
I have installed everything (services, inputstream, autoload, ctools)
I configured the REST server as follows :
Response formatters : json
Request parsing : application/json & application/x-www-form-urlencoded
gave a path to endpoint and no authentification
ticked all ressources.
The server works well : when I go to http://www.mysite.com/endpoint/node, It downloads a json with all content types (which is cool)
when I go to http://www.mysite.com/endpoint/node/-nid- I get all the information I want on the node.
Now to access this information from an outside non drupal site, I use this code:
$(document).ready( function() {
$.ajax({
type: 'GET',
url: 'http://mysite.com/endpoint/node',
dataType: "json",
success: function(data){
alert(data);
}
});
});
I tried some other requests but I allways get an empty data (200 OK though).
I could use php file_get_contents to get the info but it doesn't seem right it feels like cheating ;)
Please, can someone tell me what is missing ?
Many thanks
Comments
Maybe ...
there is a permission to be set ?
Good idea
Well i thought about it but I don't see why this would be necessary (at least for what i'm trying to achieve right now).
So if I activate authentification, any Idea on how to proceed on client side ?
Did you ever figure this out?
Did you ever figure this out? I'm having the exact same problem.
Oh services!
Services is far from perfect in its responses, but it tries. Some are very much less than useful (or downright misleading), but it is possible to get it working for most use cases.
TL;DR --
For crossdomain JSON in jQuery, turn:
http://example.com/endpoint/node/1.json into
http://example.com/endpoint/node/1.jsonp?callback=?
With this one specifically, what worked for me and goron (he works with me and I debugged it locally) is that you suggest a JSON reponse from .json, but from a third party domain or sub-domain, you need to use JSONP. The P is padding, and basically it allows jQuery to include the request into the current page as a new <script> tag, allowing for cross domain communication, but requiring a "callback=?" parameter to be added to the request URI so that as soon as the script is loaded, jQuery can grab/route the data to your callback.
I highly recommend reading up on the jQuery.getJSON() API docs, where the basics of JSON requests and JSONP implementation can be found. Good luck!