如何使用java从任何webdomain或本地系统读取特定IP地址上的文件?
我有一个程序在特定的如何使用java从任何webdomain或本地系统读取特定IP地址上的文件?,java,jquery,ajax,Java,Jquery,Ajax,我有一个程序在特定的IP上运行,并将输出放在同一系统的文件中。 我想从jsp页面使用ajax和jquery从其他系统或域(web)读取该文件 我收到不允许跨浏览器原点的错误 如何解决此错误以发出跨浏览器ajax请求 提前感谢您。如果我将数据类型指定为jsonp,是否需要添加回调函数?是的,您需要。在服务器端也是如此。我如何在服务器端定义它?见下面我的答案。我已经解释了一切。我如何处理.java页面上的回调??或者没有必要处理它??您已经在解决方案中指定了它,但我在line out.println
IP
上运行,并将输出放在同一系统的文件中。我想从jsp页面使用ajax和jquery从其他系统或域(web)读取该文件 我收到不允许跨浏览器原点的
错误
如何解决此错误以发出跨浏览器ajax请求
提前感谢您。如果我将数据类型指定为jsonp,是否需要添加回调函数?是的,您需要。在服务器端也是如此。我如何在服务器端定义它?见下面我的答案。我已经解释了一切。我如何处理.java页面上的回调??或者没有必要处理它??您已经在解决方案中指定了它,但我在line out.println(req…)上遇到了错误。。。。。。
$.ajax({
url: url,
dataType: "jsonp",
success: function (data) {
console.log(data)
alert(data);
}
});
You can’t query domain B via ajax on domain A's page.
javascript load is allowed as an exception. (We are loading fb and twitter js the same way)
Workaround:
Jquery has provided method getJSON which expects a js return from server. All we need to do is to pass
a '?' as a parameter value. In following case,
we are passing 'callback' parameter with value '?'
$.getJSON('http://www.otherserver.com/somedestination.htm?callback=?','firstname=Jeff',function(res){
alert('logged in: '+res.some_text);
});
For this call, JQuery will call server as:
http://www.otherserver.com/somedestination.htm?
callback=jQuery16200023653062526136637_1386745308424&firstname=Jeff&_=1386745308439
Now if we look closely, the value for '?' is : jQuery16200023653062526136637_1386745308424.
JQuery creates a global JS function in window DOM named
jQuery16200023653062526136637_1386745308424(response)
At server we extract this parameter (callback) and make a function String. In this function we will pass
the value we want to return to the Browser:
out.print(request.getparameter("callback")({'some_text' : '23897932823sdfhsdkfvhs32432'})
This will return
jQuery16200023653062526136637_1386745308424(({'some_text' : 'value of the text output'})
to the browser
Jquery will execute this function and will pass the string to our getJSON function parameter.