Jquery getJSON() doesn't work when trying to get data from java server on localhost
Posted
by bellesebastien
on Stack Overflow
See other posts from Stack Overflow
or by bellesebastien
Published on 2010-05-24T08:58:50Z
Indexed on
2010/05/24
9:01 UTC
Read the original article
Hit count: 443
The whole day yesterday I've been trying to solve this but it's proven to be very challenging for me.
I'm trying to use this JS to get information from a java application I wrote.
$(document).ready(function() {
$.getJSON('http://localhost/custest?callback=?', function(json) {
alert('OK');
$('.result').html(json.description);
});
});
The Java application uses httpServer and is very basic.
When I access the page 'http://localhost/custest?callback=?' with Firefox, the browser shows me the server is sending me json data and asks with what to open it with, but when I try it from a webpage using the JS above it doesn't work. The getJSON call is not successful, the alert("ok") doesn't popup at all.
If it replace "http://localhost/custest?callback=?" in the JS with "http://twitter.com/users/usejquery.json?callback=?" everything works fine.
An interesting thing is that if I send malformed JSON from my java server Firebug gives an error and tells me what is missing from the JSON so that mean the browser is receiving the JSON data, but when I send it correct a JSON string nothing happens, no errors, not even the alert() opens.
I'm adding the headers in case you think these could be relevant.
http://localhost/custest?callback=jsonp1274691110349
GET /custest?callback=jsonp1274691110349 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json
Thanks for your help
© Stack Overflow or respective owner