Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
La primera prueba jquery/ajax no funciona

Estoy tratando de utilizar jQuery/Ajax más en mis proyectos web, como prueba que he hecho: Código HTML

 <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>

Guion

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

El contenido de ajax-credits.php :

 <?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."); ?>

Código muy básico (o eso pensé) ¿alguien puede ver lo que he hecho mal? No se muestra nada en el div, ¿hay algún problema?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Intente eliminar echo "Loading"; y reemplazando

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

por

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

(Lo que sea que haga eco en el script PHP llamado por una función jQuery AJAX es lo que se envía de vuelta a la función AJAX, así que eso es lo que se cargará en su div HTML).

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!