0

次のgetJSONリクエストがあります。

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

私のテストでは、アプリケーションを「localhost:8080」で実行しており、このgetJSONをここからJSPで実行し、HTTPサーバーを「localhost:8090」で実行しています。

上記のgetJSONで使用しているURLは、このHTTPサーバーのURL、つまり「http:// localhost:8090/json」です。これは利用可能です。このURLで、JSONベースの文字列を出力しています。

したがって、getJSONで、HTTPサーバーページに表示されているデータからこのデータを取得したいと思います。

しかし、それは機能しません。

これは私のHTTPサーバーコードです:

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);
    }
}   

フリッカーからの画像を使用してgetJSONのJQUERYのWebサイトから例を実装しましたが、getJSON呼び出しでこの文字列データを取得するにはどうすればよいですか?

4

1 に答える 1

0

通常$.getjsonpデータ型を使用してみてください。

$.get(url, {
    postData: myText
}, function(data) {
    alert('data : ' + data);
}, 'jsonp');
于 2012-07-13T15:23:28.317 に答える