Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Cordova - jquery ajax post to php on server

I want to create an token based system, where I want to push the value of an input field to my server side php file to insert it into my database.

Cordova html:

<input type="text" class="valueToken" name="usertoken" >
<button class="postToken">PostToken</button>

Cordova js:

$('.postToken').click(function(){
  console.log($('.valueToken').val());
  var tokenValue = $('.valueToken').val();

$.ajax({
    type: "POST",
    url: "http://domainName.com/fysioWebapp/php/get_token.php",
    data: { 'dataString': tokenValue },
    cache: false,
    success: function(){
        alert("Order Submitted");
    }
});

});

And here is my serverside php:

<?php
include("connect.php");

$stringData = $_POST['tokenValue']; 
echo $stringData

$insertToken = "INSERT INTO User_Token VALUES ('$stringData')";
$tokenresult = mysqli_query($conn, $sql);

 if($tokenresult){
    echo "Successful";
}else {
        echo("Error description: " . mysqli_error($conn));
}

?>

But it is not posting the data to my get_token.php file what am I missing here?

With this as error on the cordova side: POST http://domainName.com/fysioWebapp/php/get_token.php 500 (Internal Server Error)

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Edit:

500 Internal Server Error will be shown if your php code has fatal errors like syntax errors and error displaying is switched off.

In your php file try adding:

ini_set('display_errors', 1);

In .htaccess file add:

php_flag display_errors 1

Found a similar answer when looking how to debug 500 errors in PHP.

Original:

Try this code.

JS

$('.postToken').click(function(){
   console.log($('.valueToken').val());
   var tokenValue = $('.valueToken').val();

   $.ajax({
       type: "POST",
       url:  "http://domainName.com/fysioWebapp/php/get_token.php",
       data: { dataString: tokenValue },
       cache: false,
       success: function(){
          alert("Order Submitted");
          }
   });
});

PHP

<?php
include("connect.php");

$stringData = $_POST['dataString']; 

echo $stringData

$insertToken = "INSERT INTO User_Token VALUES ('$stringData')";
$tokenresult = mysqli_query($conn, $insertToken);

if($tokenresult){
    echo "Successful";
}else {
    echo "Error description: " .  (mysqli_error($conn));
}
?>
about 4 years ago · Santiago Trujillo Relatório

0

I have put some names/values almost identical to yours, but I make a little difference with Ajax because I'm used to do that way... you'll have to adapt to your needs :) EDIT: you did not get the proper $vars in get_token.php because using wrong name.

<script type="text/javascript">

$(document).ready(function(){

$("#submit").click(function(e){
   e.preventDefault();

   console.log($('.valueToken').val());
   var tokenValue = $('.valueToken').val();

    $.ajax({
        method: "POST",
        url: "get_token.php",
        data: "token="+tokenValue,
        success: function(html){ alert(html); }
    });
  });
});
</script>

<form action="#" id="form" method="post">
<input type="text" class="valueToken" name="usertoken" >
<input type="submit" class="postToken" id="submit" value="PostToken" />
</form>

/-- get_token.php --/

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$token = $_POST['token'];

echo"[ $token ]";

?>
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda