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

162
Visualizações
First jquery/ajax test not working

I'm trying to utilize jQuery/Ajax more in my web projects, as a test I have done: HTML Code

<div id="main_content"></div>
<div class="panel panel-primary">
    <div class="panel-heading">API Credits Left.</div>
    <div class="panel-body">
        <form id="frmAjax" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" class="form-horizontal container-fluid" role="form">
            <div class="row form-group">
                <div class="col-sm-12 text-right">
                    <button type="submit" name="submit" class="btn btn-default">Check the API credits...</button>
                </div>
            </div>
        </form>
    </div>
    <div class="panel-footer"><b>DomDetailer</b> & <b>SeoKicks</b> Api credits left.</div>
</div>

Script

$(function() {
$(document).ready(function(){
    $('#frmAjax').submit(function() {
      $("#main_content").load('ajax-credits.php');
    });
  });
});

The ajax-credits.php contents:

<?php
  echo "Loading...";
  // http://site1.com/api/checkBalance.php?apikey=QRUE8VTQMD5Fj6&app=
  $json1 = file_get_contents('http://site1.net/api/checkBalance.php?apikey=QRUE8VTQMD5F6&app='); 
  $data1 = json_decode($json1, true);
  $valu1 = $data1[1];
  // seokicks 
  $json2 = file_get_contents('http://www.site2.net/V1/inlinkData?appid=p2hFacSWU0&output=json&details=api_credits'); 
  $data2 = json_decode($json2);
  $valu2 = $data2->Overview->credits->available;
  // display
  stdmsg("Site 1 has <b>".$valu1."</b> credits left and Site 2 has <b>".$valu2."</b> credits left.");
?>

Very basic code (or so I thought) can anyone see what I have done wrong? Nothing is being displayed in the div , is there any issue?

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

0

Try removing echo "Loading"; and replacing

    stdmsg("Site 1 has <b>".$valu1."</b> credits left and Site 2 has <b>".$valu2."</b> credits left."); 

by

    echo "<p>Site 1 has <b>".$valu1."</b> credits left and Site 2 has <b>".$valu2."</b> credits left.</p>";

(Whatever you echo in the PHP script called by a jQuery AJAX function is what gets sent back to the AJAX function, so that is what will get loaded into your HTML div.)

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