0

我有以下 getJSON 请求:

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

对于我的测试,我有一个在“localhost:8080”上运行的应用程序,我正在 JSP 中从这里执行这个 getJSON,并且在“localhost:8090”上运行一个 HTTP 服务器。

我在上面的 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);
    }
}   

我已经使用来自闪烁的图像实现了 JQUERY 网站上的 getJSON 示例,但是如何在 getJSON 调用中取回这个字符串数据?

4

1 回答 1

0

$.get尝试使用带有数据类型的常规jsonp

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