Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
$.post fails when including php file

I'm making a $post call to a .php file that return json data. It works just fine if I only use one .php, but if I try including another .php it drops into the .failed callback. I've put together an example here with an included .php that doesn't even do anything.

Javascript:

$.post("/test_php/cgi.php", l_cDB_arg_array, function(o) {
  console.log("Returned from db_interface call" + JSON.stringify(o));
  console.log(JSON.stringify(o));
  l_this.showLayer("top of the world", false);
}).fail(function(response) {
  console.log('Error: ' + JSON.stringify(response));
});

First cgi.php:

<?php
include "noop.php";

header("Content-Type: application/json; charset=UTF-8");


$ret = json_decode('{"some":"data"}');

echo json_encode($ret);

Second noop.php

<?php

Result when including noop.php in cgi.php

Error: {"readyState":4,"responseText":"{\"some\":\"data\"}","status":200,"statusText":"OK"}

Result when not including noop.php in cgi.php

Returned from db_interface call{"some":"data"}

Looking at all the .fail arguments I get:

response: {"readyState":4,"responseText":"{"some":"data"}","status":200,"statusText":"OK"}

textStatus: parsererror

errorThrown: SyntaxError: Unexpected token in JSON at position 0

Moving the header to before the include didn't change anything.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Installed eclipse, and edited the noop.php with it. I could see one more line in the file with the eclipse editor, that was showing in visual studio. Deleting the extra line with eclipse solved the problem.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda