0

I have the following getJSON request:

$.getJSON(url + "&callback=?", {
    postData: myText
}, function(data) {
    alert('data : ' + data);
});

For my testing I have an applicatoin running on "localhost:8080" and I am performing this getJSON from here in a JSP, and an HTTP Server running on "localhost:8090".

The URL I am using in my getJSON above, is the URL of this HTTP Server, i.e. "http://localhost:8090/json". This is available. On this URL, I am outputting a JSON based string.

So.. in my getJSON, I want to get this data back from what is being displayed on the HTTP Server page.

But it doesn't work.

This is my HTTP Server code:

public void RunHttpServerStart() {
    HttpServer server = null;

    try
    {

       HttpJsonHandler handler = new HttpJsonHandler();
       server = HttpServer.create(new InetSocketAddress(8090), 10);
       server.createContext("/json", handler); // The handler holds my JSON string being output
       server.setExecutor(null); // creates a default executor
       server.start();

       System.out.println("Server is started");

       while(handler.shutdown == false) { Thread.sleep(1000); }

       System.out.println("Stopping server");

    }
    catch(Exception ex) { System.out.println(ex.getMessage());}
    finally { 
        if(server != null)
            server.stop(0);
    }
}   

I have implemented the example from JQUERY's website for getJSON with the images from flicker, but how do I get this string data back in the getJSON call?

Esailija
  • 138,174
  • 23
  • 272
  • 326
babb
  • 423
  • 2
  • 15
  • 38
  • 1
    You may want to specify "it doesn't work" - don't you get any response or, if you get one, what is the response? Maybe this helps: [Ajax on different ports](http://stackoverflow.com/questions/1795183/jquery-ajax-on-different-port) – Simon Jul 13 '12 at 15:32

1 Answers1

0

Try using regular $.get with a jsonp datatype.

$.get(url, {
    postData: myText
}, function(data) {
    alert('data : ' + data);
}, 'jsonp');
Naftali
  • 144,921
  • 39
  • 244
  • 303