Make a request on the server with 2 parameters

Asked

Viewed 131 times

-4

Well, I’m making a person use a "range" and decide a value, as soon as the person modifies the range, a search is being done in the database about a game and its value, use ajax with php for this, but this giving an error, you can help me?

  • 2

    When you set the value of the 'game' variable before the request, you do not put the . value, it is returning the Javascript object and not the field value, try changing.

  • of the one var_dump($_GET); so you see what your ajax is sending. probably the variable game is not being initialized

  • in his getDados() after the getelementbyid('jogo') of the one alert('jogo');see if you’re not coming as null

  • where do I dump ($_GET)?

  • I am setting game equal set value, when I command only the value it works normally, but now need to add the game as a new parameter.

  • I give an Alert(game) and the Alert doesn’t even appear on the screen

  • Let me tell you, put code instead of image to test. See this post en.meta.stackoverflow.com/questions/5483/... Do you think I’ll waste hours typing your code to test when you could post your code in 5 seconds and the guys in 5 seconds copy to make changes to it and perform tests to make sure that the fix took effect and give you a correct answer? Read this post https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5485#5485

Show 2 more comments

3 answers

1

Good morning,

From what I understand it is only to put . value at the end of Document.getElementById('game')

var jogo = document.getElementById('jogo').value;

You are trying to send the input game and not the value of the field in this code

  • I have done with . value however keeps giving the same error

  • There is an error in the console?

  • Super weird, your script is running these parts, it was only by the value at the end of the element. I ran some tests here, maybe it’s the browser or something

0

Test there to check if the request is going with the two parameters.

"php/select-coach.php? value=1&game=3"

function criarReq() {
    try{
        return new XMLHttpRequest();
    } catch (e) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e) {
                console.log("Seu navegador não suporta Ajax!");
                //return null;
            }
        }
    }
}

function getDados() {
    var valor = document.getElementById('coachValue').value;
    var coach = document.getElementById('coachs');
    var jogo = document.getElementById('jogo').value;
    var xmlreq = new criarReq();
    
    console.log("php/select-coach.php?valor="+valor+"&jogo="+jogo);
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <input type="range" id="coachValue" value="1">
  <input type="text" id="coachs" value="2">
  <input type="text" id="jogo" value="3">
  
  
  <input type="button" value="send" onclick="getDados()">
</body>
</html>

-3

Friend, on line 6 it’s like this:

$jogo=intval($_GET['jogo']);

change this part leaving so:

$jogo=$_GET['jogo']; 
  • 1

    Dude, there’s no point in taking the intval. Because you think it’s the solution?

  • simply not knowing what information is coming in. However I know that there is an invalid or empty value

  • It was a kick then?

  • Not Fernando. I do not give kick. to making the indication of own error . Above I said I do not know what information is coming there. the fact of taking the intval changes the way I will look at the code.

  • Yes. Undefined index 'jogo' on line 6. But take out the intval will not change anything, alias the intval will pick up any value he can’t convert and return 0. Your answer does nothing. That’s why I asked.

  • 1

    Calm young, did not know you were speaking in another language, does not need translation. His answer would fit more like a comment (which is the exact comment Jasar asks him to make var_dump($_GET);). And my question was genuine, your answer (as an answer) does nothing. And I’m not going to give any answers because there’s not enough information to give a decent answer. You need to learn to calm down, I don’t know you, this is not an attack. Relax.

  • I appreciate criticism. I appreciate attacks as well. Changing an intval to another value changes everything. how an entire field will receive a char? he will give indefinite friend. so let the owner test. that’s how I do.If the answer does not suit you can serve for him.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.