如何使用jQUERY Ajax调用不同端口的JSP?放入不同目录时无响应
The html is on the
C:/xampp/htdocs/load/index.html
The jsp is on the
C:/xampp/tomcat/webapps/ROOT/jspmysql/load.jsp
the code in the index.html is as follow:
ajax({
type:"GET",//POST cannot work when the two files in the same tomcat directory.I donnot know why?
dataType: 'jsonp',
//I chang this to "json" will work well when I put the two files in the same tomcat directiory and use the http://localhost:8080/index.html.But not the "jsonp".
//json and jsonp don't work and get the ajax error message.
contentType: "application/json; charset=utf-8",
data: {
Esites:123,
Ssites:456
},
url: 'http://127.0.0.1:8080/jspmysql/load.jsp',
error: function(xhr) {
alert('Ajax request error');
},
success: function (response) {
alert("succeed");
alert("suceed="+response.msg); // do stuff
},
complete: function () {
alert('After Send'); //this was fired
}
});
the load.jsp is as follows:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<%
request.setCharacterEncoding("UTF-8");
String es = request.getParameter("Esites");
String ss = request.getParameter("Ssites");
out.println("{\"msg\": \"newsvgtemple.svg\",\"Esites\":\""+es+"\", \"Ssites\":\""+ss+"\"}");
%>
但是当我运行index.html时 我得到了误差函数。 请问这种情况怎么解决?是跨域问题吗?不同的问题可以在 http://blog.yam.com/u9323523/article/25178591< /a> php 和 jsp 一起工作。我可以在 xampp 上做同样的事情吗?
The html is on the
C:/xampp/htdocs/load/index.html
The jsp is on the
C:/xampp/tomcat/webapps/ROOT/jspmysql/load.jsp
the code in the index.html is as follow:
ajax({
type:"GET",//POST cannot work when the two files in the same tomcat directory.I donnot know why?
dataType: 'jsonp',
//I chang this to "json" will work well when I put the two files in the same tomcat directiory and use the http://localhost:8080/index.html.But not the "jsonp".
//json and jsonp don't work and get the ajax error message.
contentType: "application/json; charset=utf-8",
data: {
Esites:123,
Ssites:456
},
url: 'http://127.0.0.1:8080/jspmysql/load.jsp',
error: function(xhr) {
alert('Ajax request error');
},
success: function (response) {
alert("succeed");
alert("suceed="+response.msg); // do stuff
},
complete: function () {
alert('After Send'); //this was fired
}
});
the load.jsp is as follows:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<%
request.setCharacterEncoding("UTF-8");
String es = request.getParameter("Esites");
String ss = request.getParameter("Ssites");
out.println("{\"msg\": \"newsvgtemple.svg\",\"Esites\":\""+es+"\", \"Ssites\":\""+ss+"\"}");
%>
But when I run the index.html
I got the error function.
How do I fix the situation?Is it the cross-domain question? The different can be solve on the http://blog.yam.com/u9323523/article/25178591 php and jsp work together.Can I do the same thing on the xampp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你确定你的java服务器运行在8080端口上吗?如果是这样,那么这里调用 JSP 的方法是正确的。
500 - 内部服务器错误意味着 JSP 页面上存在一些错误,而不是您调用它的端口上存在错误。尝试在另一个浏览器窗口中调用不使用 jQuery 的 JSP 页面,并查看得到的输出。如果仍然是 500 错误,那么您的 JSP 中存在编码问题,而不是 jQuery 中的问题。
First of all, are you sure that your java server is running on port 8080? If so, then what you have here is correct for calling the JSP.
The 500 - Internal Server Error means that there was some error on the JSP page, not the port you're calling it on. Try calling the JSP page without jQuery, in another browser window, and see what output you get. If it is still a 500 error, then you have a coding problem in your JSP, not with your jQuery.