[英]Problems passing data to jquery's getJSON() - Will not accept map
[英]JQUERY - getJSON - issue with returning the data item
我有以下getJSON請求:
$.getJSON(url + "&callback=?", {
postData: myText
}, function(data) {
alert('data : ' + data);
});
對於我的測試,我有一個在“ localhost:8080”上運行的應用程序,並且我正在此處從JSP中執行此getJSON,並在“ localhost:8090”上運行一個HTTP Server。
我在上面的getJSON中使用的URL是此HTTP Server的URL,即“ http:// localhost:8090 / json”。 這是可用的。 在此URL上,我正在輸出基於JSON的字符串。
因此,在我的getJSON中,我想從HTTP Server頁面上顯示的內容中獲取該數據。
但這是行不通的。
這是我的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調用中獲取此字符串數據呢?
嘗試將常規$.get
與jsonp
數據類型一起使用。
$.get(url, {
postData: myText
}, function(data) {
alert('data : ' + data);
}, 'jsonp');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.