weixin_33681778 2013-02-28 21:24 采纳率: 0%
浏览 382

求助:Ajax请求出现404错误

我需要用ajax从数据库的JSP页面中获取一些数据,然后放入div中。

这是我的代码:

$(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");

问题是,除了 xhr.status 所呈现的thrownError和未发现404错误之外,ajax内容没有馈入div。

有人能帮帮我吗?

  • 写回答

2条回答 默认 最新

  • weixin_33724570 2013-02-28 21:33
    关注

    Either, busca-notas.jsp does not exist, or it is on a different server or path as the HTML calling the Ajax request.

    Example: If your HTML and JavaScript is here:

    http://www.example.com/somepath/page.html
    

    and your PHP code is here:

    http://www.example.com/otherpath/busca-notas.jsp
    

    then you'll Need to use url: "../otherpath/busca-notas.jps". There is an easy way to check: Open your HTML in the browser, remove the last bit of the path, and replace it with "busca-notas.jpg", and see what you're getting.

    A 404 also means, your JSP code never gets executed.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料