I am making a Windows Service in delphi XE2. So far I have set a TTCPServer to listen on port 7777, it has access to all data passed through. I am trying to get it to receive data, run a query based on the data passed through, then return a JSON file. To create the JSON file I have to write the headers line by line then the JSON data.
Here is what i have got so far :
HTTP/1.0 200 OK
Content-Type: application/json
Accept: application/json
Content-Length: 294
Content-Type: application/json
Cache-Control: no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT
{"completed_in":0.031,"remote_ip":"202.45.110.174","date_time":"20:45:00 08/04/2
012","number_of_results":2,"query":"SELECT * FROM XUSER","success":1,"error_msg"
:"","results":[{"user_name":"BRAD","web_enabled":1,"first_name":"Bradly"},{"user
_name":"JOHN","web_enabled":0,"first_name":"John"}]}
jQuery Code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Accrivia Test</title>
<script type="text/javascript" src="../jquery-1.7.2.min.js"></script>
</head>
<body>
<input type="text" id="query" value="Twitter" /><button>search</button><br /><br />Results :<hr /><br />
<div id="results">
</div>
<script type="text/javascript">
$(document).ready(function(){
var url='http://brad:7777/search.json?callback=?';
$('button').click(function(){
alert("1");
$.getJSON(url,function(json){
alert("2");
$.each(json.results,function(i,user){
alert("3");
$("#results").append('<p>'+user.user_name+' - '+user.first_name+'</p>');
if (i == 3) return false;
});
});
});
});
</script>
</body>
</html>
It shows alert(1) but none of the others... I have been trying to make it similar to the Twitter search API.
If I open 'http://brad:7777/search.json?callback=?' i get a prompt to download search.json and firebug shows the JSON content in the JSON section and nothing in the response body.
I have tried to write the $.getJSON part in the console but json.* (json.anything) is always undefined.
This is the first one that i have tried cross domain, but from my reading i have to have specified a callback in the URL and it should use JSONP?
The twitter example works no problem and any others i have made (here) that are on a single domain work also.


Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.
Back to top








