Angularjs - request Does not pass parameter

Asked

Viewed 74 times

0

My code is this, but in php code I do not receive the ref parameter... What can be ?

$http({
         method: 'POST',
         url:  '../assets/php/client/PHP.php',
         data: {ref: 'dataTableLoad'}
         }).then(function (response) {// on success
         //alert(response.data);
         console.log(response.data);
         $('#dataTableTboody').html(response.data);},
         function (response) {
         console.log(response.data,response.status);
         }); 
My php needs this way :

if (isset($_POST['ref']) && $_POST['ref'] != '') {
    init($_POST['ref']);
} else {
    $data['response'] = -1;
    echo json_encode($data);
    exit;
}
He only returns me -1 Thank you

  • Run a test to see if it’s not coming in the input stream with file_get_contents('php://input') , if you are just use json_decode to return the input

2 answers

1


Check that in $POST comes the date object, if I’m not too rusty in PHP this code below should work if the object comes as a date

if (isset($_POST['data']->ref) && $_POST['data']->ref != '') {
    init($_POST['data']->ref);
} else {
    $data['response'] = -1;
    echo json_encode($data);
    exit;
}

1

You’re passing the literal string 'dataTableLoad' to the server.

I imagine you want to pass the value of dataTableLoad. Try it like this:

$http({
     method: 'POST',
     url:  '../assets/php/client/PHP.php',
     data: {ref: dataTableLoad} // Perceba que retirei as aspas simples.
  • gave another error : Referenceerror: dataTableLoad is not defined

  • I actually need to pass the literal string value... that’s the value I need to pass

  • @Augustofurlan so you are trying to pass a variable that has never been defined.

  • @Onesendai is actually not variable, but rather direct string ....

Browser other questions tagged

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