我需要从JSP页面中获取一些数据,这些数据在数据库上执行select,然后放入div中.我需要用ajax做到这一点.
这是我的代码:
$(function() {
teste();
});
function teste() {
var v1 = document.getElementById("selCodigo").value;
alert(v1);
$.ajax({
type : "GET",
data : "turma="+v1,
url : "busca-notas.jsp",
success : function(resposta){
alert("DEU CERTO");
},
error : function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
document.getElementById("notas").innerHTML = "ERRO";
}
});
}
我测试了变量v1及其接收所需的值,在我的JSP页面中,我这样做:
String turmaSelecionada = request.getParameter("turma");
问题是没有输入div的ajax内容需要超出xhr.status提出的thrownError并且找不到404错误
谁能帮我?
解决方法:
或者,busca-notas.jsp不存在,或者它与调用Ajax请求的HTML位于不同的服务器或路径上.
示例:如果您的HTML和JavaScript在此处:
http://www.example.com/somepath/page.html
http://www.example.com/otherpath/busca-notas.jsp
那么你需要使用url:“.. / otherpath / busca-notas.jps”.有一种简单的方法可以检查:在浏览器中打开HTML,删除路径的最后一位,然后将其替换为“busca-notas.jpg”,看看你得到了什么.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。