今天练习jquery跨域的时候,遇到以下问题: 总是出现拒绝访问 jquery-1.4.2.js 行5113 代码0 的错误
今天练习jquery跨域的时候,遇到以下问题:总是出现拒绝访问jquery-1.4.2.js行5113代码0的错误具体代码如下:请高手指点(最好帮忙测一下)我新建了两个w...
今天练习jquery跨域的时候,遇到以下问题: 总是出现拒绝访问 jquery-1.4.2.js 行5113 代码0 的错误 具体代码如下:
请高手指点(最好帮忙测一下)
我新建了两个web项目
一个只写了一个servlet 另一个只写了页面
servlet:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
public class Login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String jsoncallback = request.getParameter("jsoncallback");
JSONObject json = new JSONObject();
json.put("name", "zhagnsan");
PrintWriter out = response.getWriter();
out.print(jsoncallback + "("+json.toString()+")");
out.flush();
out.close();
}
}
页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(function(){
$("#button").bind("click",function(){
$.get("http://localhost:8080/testKuaYu/login.do?jsoncallback?",function(data){
alert(data.name);
});
});
});
</script>
</head>
<body>
<input type="button" id="button" value="click"/>
</body>
</html>
第一次遇到跨域问题,请高手解决!
一个项目部署到myeclipse自带的tomcat,另一个项目部署到安装的tomcat 展开
请高手指点(最好帮忙测一下)
我新建了两个web项目
一个只写了一个servlet 另一个只写了页面
servlet:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
public class Login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String jsoncallback = request.getParameter("jsoncallback");
JSONObject json = new JSONObject();
json.put("name", "zhagnsan");
PrintWriter out = response.getWriter();
out.print(jsoncallback + "("+json.toString()+")");
out.flush();
out.close();
}
}
页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(function(){
$("#button").bind("click",function(){
$.get("http://localhost:8080/testKuaYu/login.do?jsoncallback?",function(data){
alert(data.name);
});
});
});
</script>
</head>
<body>
<input type="button" id="button" value="click"/>
</body>
</html>
第一次遇到跨域问题,请高手解决!
一个项目部署到myeclipse自带的tomcat,另一个项目部署到安装的tomcat 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询