3
How do I get Ajax to get the current URL? Here are the values that go to php. If I do so it works
jQuery.ajax({
url: "http://localhost/jogoteocratico/consulta.php?dificuldade=1&rodada=1",
type: "GET",
dataType: 'json',
success: function(returnjson) {
var i=0;
$('#proxima').click(function exibir(){
i++;
document.getElementById("id_pergunta").innerHTML = returnjson[i].id_pergunta;
document.getElementById("pergunta_jogo").innerHTML = returnjson[i].pergunta;
document.getElementById("desafio_jogo").innerHTML = returnjson[i].desafio;
document.getElementById("resposta_jogo").innerHTML = returnjson[i].resposta;
});
But if I do it like this, it doesn’t work:
$(document).ready(function mostrarPergunta(){
var url = window.location.href;
jQuery.ajax({
url: url,
type: "GET",
dataType: 'json',
success: function(returnjson) {
// for(i=0; i<returnjson.length; i++){
// alert(returnjson[i].pergunta);
//}
var i=0;
$('#proxima').click(function exibir(){
i++;
document.getElementById("id_pergunta").innerHTML = returnjson[i].id_pergunta;
document.getElementById("pergunta_jogo").innerHTML = returnjson[i].pergunta;
document.getElementById("desafio_jogo").innerHTML = returnjson[i].desafio;
document.getElementById("resposta_jogo").innerHTML = returnjson[i].resposta;
});
What is the difference between the two examples? To use the current query string you can do
url: "/jogoteocratico/consulta.php" + location.search,
– Sergio
@Thank you very much.
– Tiago Silveira