3

spent a few hours trying to figure this out, but cannot for the life of me figure out what's going wrong.

All I'm trying to do is load this:

https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json

which I believe is json, into either javascript/jquery or php and use the data.

I've looked into jsonp, followed some tutorials, used some demos as templates and just can't get the above data to work.

If anyone can shed some light it would be much appreciated. It really shouldn't be this complicated, but I don't know what's going wrong.

hakre
  • 193,403
  • 52
  • 435
  • 836
Derek Ho
  • 35
  • 1
  • 1
  • 4
  • Question needs more detail; show us your code. But at a wild guess, I'd say you're probably running into cross-domain security restrictions. – Will Martin Dec 01 '11 at 16:22
  • it's a recruitment website, I'm trying to show the 5 latest job openings. To be honest I've just been trying to copy tutorials and demos with the above link. – Derek Ho Dec 01 '11 at 16:43

3 Answers3

10

Yep, that's JSON. The site may not support JSONP, so you're gonna have to use PHP to do this.

This is untested, but should work.

<?php
$url = 'https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json';
$JSON = file_get_contents($url);

// echo the JSON (you can echo this to JavaScript to use it there)
echo $JSON;

// You can decode it to process it in PHP
$data = json_decode($JSON);
var_dump($data);
?>
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • thanks for this! seems to be a step forward in the right direction. ideally it would be useful if I can use it in php, but the var_dump is returning null... echoing it works fine so may use JS. – Derek Ho Dec 01 '11 at 16:47
  • @DerekHo: Weird, maybe there are some characters it doesn't like or something, I'm not sure. – gen_Eric Dec 01 '11 at 16:54
  • I can decode and dump the actual data (if I said $JSON = 'data')... but I cannot decode and dump $JSON = file_get_contents($url); very strange... – Derek Ho Dec 01 '11 at 17:11
  • 1
    ...so apparently £ signs aren't allowed in JSON. A simple str_replace() sorted that out. thanks for your help. – Derek Ho Dec 06 '11 at 11:28
  • @DerekHo: Glad you figured it out, I'm happy to help :-) – gen_Eric Dec 06 '11 at 14:08
5

JSONP relies on the server to return a JSONP formatted response. Basically, to use JSONP the server needs to return a JSON string wrapped in a function invocation ({"foo":1} becomes func({"foo":1})).

As the server your using doesn't return a JSONP response, you cannot use JSONP, you can only use JSON.

This is a shame, as JSON cannot be used x-domain due to the same origin policy (SOP). Therefore, the only option you have is to use a proxy server, which retrieves the JSON from the server, and either gives it to you in JSONP (see Yahoo Pipes), or which is on the same domain as the requested page (write a simple PHP script to get the file using file_get_contents() and then echo the output), in which case it can return the JSON.

Community
  • 1
  • 1
Matt
  • 74,352
  • 26
  • 153
  • 180
0

I breifly looked at the requirements and it looks like you need an API key as well as an account. I saw that the site provides services for XML and JSON only. It looks to be fairly well documented.