I need to grab some data from a JSP page that does a select on a database and then put inside a div. I need to do this with ajax.
Here is my code:
$(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";
}
});
}
I tested the variable v1
and the value that it receives necessary, and in my JSP page, I do this:
String turmaSelecionada = request.getParameter("turma");
the problem is that the ajax content that does not feed into the div need, beyond what the xhr.status
presents thrownError and a 404 error not found
Can anyone help me?
I need to grab some data from a JSP page that does a select on a database and then put inside a div. I need to do this with ajax.
Here is my code:
$(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";
}
});
}
I tested the variable v1
and the value that it receives necessary, and in my JSP page, I do this:
String turmaSelecionada = request.getParameter("turma");
the problem is that the ajax content that does not feed into the div need, beyond what the xhr.status
presents thrownError and a 404 error not found
Can anyone help me?
Share Improve this question edited Feb 28, 2013 at 21:28 Ry-♦ 225k56 gold badges491 silver badges498 bronze badges asked Feb 28, 2013 at 21:24 Daniel SwaterDaniel Swater 2371 gold badge6 silver badges20 bronze badges 2-
2
If you're getting a 404 error, the error is going to be here:
url : "busca-notas.jsp",
– Kevin B Commented Feb 28, 2013 at 21:25 - yes but this this page in the same directory – Daniel Swater Commented Feb 28, 2013 at 21:29
2 Answers
Reset to default 9Either, 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./somepath/page.html
and your PHP code is here:
http://www.example./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.
This is saying the resource you are trying to do a GET to is not there. The path you are doing a GET to is probably incorrect. Can you tell the structure of your files (javascript/service files etc...). I would suggest using the browser developer tools or fiddler to debug what is going on.
Use F12 (windows) with browsers to get to the developer tools. Also the fiddler tool is great! http://www.fiddler2./fiddler2/
On a side note if you use console.log for debugging you will never go back to alerts :)