Kajcioch Kajcioch - 3 months ago 10
PHP Question

Blank result in Ajax PHP

Every time I do an Ajax request, I want server to check if number is 1, 3 or 5, and depending on result, echo out answer. The problem is, I get no

data
in my
alert();
. Here's my code:

ajax:

ajaxNumber= $.ajax({
url: "operations.php",
type: "post",
data: ile,
success: function(data){alert(data);}
});


PHP:

if(isset($_POST['ile'])) {
$numer = intval($_POST['ile']);
if($numer==1|$numer==3|$numer==5) {
echo "ok";
} else {
echo "ERROR";
}
}


alert();
is being displayed, but it's just empty.

enter image description here

EDIT: Running
operations.php
on my own and giving $_POST['ile'] an existing value echos out me good responses.

Ali Ali
Answer

you don't set ile name so $_POST['ile'] is empty, try this :

ajaxNumber= $.ajax({
        url: "operations.php",
        type: "post",
        data: {'ile':ile},
        success: function(data){alert(data);}
    });